私は現在Pythonを学んでいて、たくさんのことを知っているわけではないので、ここで私を助けてくれる経験豊富な人が必要です。この迷惑なエラーメッセージを回避するにはどうすればよいですか? (Python 3.6.1)
がusernum = input('Enter a number, Ill determine if its pos, neg, OR Zero.')
if usernum < 0:
print("Your number is negative.")
if usernum > 0:
print("Your number is positive.")
if usernum == 0:
print("Your number is zero.")
エラーはこれです:
コードはこれです
usernum = int(input('Enter a number, Ill determine if its pos, neg, OR Zero.'))
あなたはそれを持っていたようにあなたの最初の行
Traceback (most recent call last):
File "C:\Users\Admin\Documents\Test.py", line 2, in <module>
if usernum < 0:
TypeError: '<' not supported between instances of 'str' and 'int'
「usernum」は文字列です。 'int(usernum = input( '数字を入力すると、そのpos、neg、ORがゼロかどうかを判断する)'))' –
http://stackoverflow.com/questions/379906/parse-string-to -float-or-int - 浮動小数点数も忘れないでください。 – stdunbar