所以,當談到編程時,我是一個完整的newb。我一直在看教程,我正在閱讀一本關於如何編程python的書。所以,我想自己創建一個數字發生器猜測器,我已經看過一些教程,但我不想重新創建代碼。基本上,我想用我得到的信息做我自己的猜測。隨機數猜測器
import random
# Random Numbergenerator Guesser
print("Hello and welcome to the random number guesser.")
print("I am guessing a number of 1 - 20. Can you guess which one?")
x = random.randint(1,20)
# Here you guess the number value of 'x'
for randomNumber in range (1,7):
randomGuess = input()
if randomGuess > x:
print("Too high. Guess again!")
elif randomGuess < x:
print("Too low. Guess again!")
else:
break
# Checks to see if the number you were guessing is correct or takes you to a fail screen.
if randomGuess == x:
print("Correct number!")
else:
print("Too many tries. You have failed. The number I was thinking of was " + (x))``
我不斷收到此錯誤。
C:\Python\Python35\python.exe "C:/Users/Morde/Desktop/Python Projects/LoginDataBase/LoginUserDatabse1File.py"
Hello and welcome to the random number guesser.
I am guessing a number of 1 - 20. Can you guess which one?
1
Traceback (most recent call last):
File "C:/Users/Morde/Desktop/Python Projects/LoginDataBase/LoginUserDatabse1File.py", line 12, in <module>
if randomGuess > x:
TypeError: unorderable types: str() > int()
使用'randomGuess = INT(輸入())' 。 –
'input()'返回一個字符串('str'對象),你需要從字符串中創建一個'int'對象。 – cdarke