我生成一个猜测'并且回答'在两个功能。如何将这些特定结果传递给后续使用' guess'并且回答'在它的论点?
import random
def generate_guess():
guess = input("Please enter a 4 digit guess: ")
print(guess)
return guess
def generate_secret():
while True:
num = random.randint(0,9999)
num = str(num)
if num[0:1] != num[1:2]:
if num[0:1] != num[2:3]:
if num[0:1] != num[3:4]:
if num[1:2] != num[2:3]:
if num[1:2] !=num[3:4]:
if num[2:3] != num[3:4]:
secret = num
print(secret)
answer = secret
return answer
break
def how_many(answer,guess):
答案 0 :(得分:0)
致电how_many(generate_secret(), generate_guess())
。如果答案不应该改变,请尝试这样做:
secret = generate_secret
while <user has not guessed the answer>
how_many(secret, generate_guess())
此外,您的generate_secret
功能纯属可怕。请尝试进行代码审查以修复该功能;它看起来非常低效且难以理解。