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