爲什麼我的程序在這裏給我一個錯誤?運行一個非常簡單的Python程序的問題
import random
TheNumber = random.randrange(1,200,1)
NotGuessed = True
Tries = 0
GuessedNumber = int(input("Take a guess at the magic number!: "))
while NotGuessed == True:
if GuessedNumber < TheNumber:
print("Your guess is a bit too low.")
Tries = Tries + 1
GuessedNumber = int(input("Take another guess at the magic number!: "))
if GuessedNumber > TheNumber:
print("Your guess is a bit too high!")
Tries = Tries + 1
GuessedNumber = int(input("Take another guess at the magic number!: "))
if GuessedNumber == TheNumber:
print("You've guess the number, and it only took you " + string(Tries) + "!")
錯誤在最後一行。我能做什麼?
編輯:
另外,爲什麼能;噸我用嘗試次數++這裏在Python?沒有自動增量代碼嗎?
編輯2:錯誤是:
Traceback (most recent call last):
File "C:/Users/Sergio/Desktop/GuessingGame.py", line 21, in <module>
print("You've guess the number, and it only took you " + string(Tries) + "!")
NameError: name 'string' is not defined
你有一個無限循環 – SilentGhost 2009-10-05 22:24:50
'string' - >'str' – jfs 2009-10-05 22:28:31
'string'沒有定義:) – OscarRyz 2009-10-05 22:34:54