import random
guesses = 3
number = random.randint(1, 10)
print (number) #<- To test what number im supposed to write.
while guesses > 0: # When you have more than 0 guesses -> guess another number
guess = input("Guess: ")
if guess == number : # If guess is equal to number -> end game
print ('Your guess is right!.')
break
if guess != number : # If not number -> -1 guess
print ("Nope!")
guesses -= 1
if guesses == 0: #If all 3 guesses are made -> end game
print("That was it! Sorry.")
print(number,"was the right answer!")
我在做什么错? 我想不出来,我希望你能帮助^ -^为什么这段代码无法正常工作(我刚接触编程,python)
如果你能教我如何改善我的编程,然后随时写我如何做到这一点!我打开学习新的东西btw对不起,我的英语不好:3(编辑:当我猜对了正确的数字,它仍然说“没有!”,我不得不猜测另一个数字。)
什么不起作用?你期望什么作为输出,什么是实际输出? – k4ppa
当我猜想正确的数字,它仍然说,猜测是错误的,所以我不知道什么是错的。 – Venx
这看起来像Python3。如果是这样,请使用'guess = int(input(“Guess:”))'。 – bernie