import random
secret = random.randint (1,99)
guess = 0
tries = 0
print ("AHOY! I'm the Dread Pirate Roberts, and I have a secret!")
print ("It is a number from 1 to 99. I'll give you 6 tries. ")
while guess != secret and tries < 6:
guess = input ("What's yer guess? ")
if guess < secret:
print ("Too low, ye scurvy dog")
elif guess > secret:
print ("Too high, landrubber!")
tries = tries + 1
if guess == secret:
print ("Avast! Ye got it! Found my secret, ye did!")
else:
print ("No more guesses! Better luck next time, matey!")
print ("The secret number was", secret)
我不斷收到此錯誤:如果猜測<祕密: 類型錯誤:unorderable類型:STR()< INT()這個Python遊戲代碼有什麼問題?
他使用Python 3'print',所以'input()'不是問題。 – 2010-08-18 16:20:41
不一定。在Python 3中'print()'是完全有效的。無論如何,編輯澄清。 – 2010-08-18 16:22:23
s/3/2。我的意思是'print' _can_可以和Python 2中的函數調用使用相同的語法,儘管我確實認爲它並不經常用於這種方式。 – 2010-08-18 16:26:34