[英]TypeError: '>' not supported between instances of 'str' and 'int' but I made the string an Interger
I have this really frustrating error that I can't seem to fix, it tells me that the "<" is not supported by strings and integers but I made sure I converted them into integers using the int() function我有一个我似乎无法修复的非常令人沮丧的错误,它告诉我字符串和整数不支持“<”,但我确保我使用 int() 函数将它们转换为整数
import random
print("Hi what is your name?")
name = input()
print("And your age please?")
age = input()
print(f"Now {name} pick a number that is lower than your age ({age}) but bigger than zero")
number_pick = input()
if number_pick != "":
int(age)
int(number_pick)
if number_pick > 0:
print(f"Good choice now the result of your {age} timesed by {number_pick} is..")
print(age * number_pick)
else:
print("your number doesnt follow the requirements")
else:
print("Please write your number pick")
I am lost for ideas, what should I change?我失去了想法,我应该改变什么?
int(number_pick)
This cast returns the result of the conversion, but you aren't storing it anywhere.此强制转换返回转换结果,但您并未将其存储在任何地方。
number_pick = int(number_pick)
You may also want to add some error checking:您可能还想添加一些错误检查:
try:
number_pick = int(number_pick)
except TypeError:
print("Please make sure you are entering in a number")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.