プログラミングでは完全な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