import random
print("Welcome to the Number Guessing Game!\n")
print("We are going to pick a number and have the computer guess it.")
answer = int(input("Pick a number between 1 and 100:\n"))
guess = random.randint(1, 100)
guesses = 1
while guess != answer:
if guess > answer:
guess = random.randint(1, guess)
print(guess)
elif guess < answer:
guess = random.randint(guess, 100)
print(guess)
guesses += 1
print("\nWhoopy, I guessed correct.\n")
print("It took me %s guesses to guess %s." % (guesses, answer))
這是我到目前爲止。我不知道如何形成如果和ELIF以確保不存在欺騙猜在while循環期間更新範圍,所以沒有愚蠢的猜測
什麼是'猜測= guess'點? – 2014-09-05 02:45:44
這可能是一段無用的代碼。讓我做一個檢查。 – SleepyViking 2014-09-05 02:51:47
這是一個疏忽。謝謝 – SleepyViking 2014-09-05 02:56:26