简体   繁体   English

类型错误:“str”和“int”的实例之间不支持“>”,但我将字符串设为 Interger

[英]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.

相关问题 TypeError:将字符串转换为浮点数后,“str”和“int”实例之间不支持“&lt;” - TypeError: '<' not supported between instances of 'str' and 'int' after converting string to float 我有这个错误 TypeError: &#39;&lt;&#39; not supported between &#39;str&#39; and &#39;int&#39; - i am having this error TypeError: '<' not supported between instances of 'str' and 'int' 我收到TypeError:“ str”和“ int”的实例之间不支持“ &lt;” - I got a TypeError: '<' not supported between instances of 'str' and 'int' 如何解决 TypeError: &#39;int&#39; 和 &#39;str&#39; 实例之间不支持的 &#39;&lt;&#39;? - How do I resolve TypeError: '<' not supported between instances of 'int' and 'str'? TypeError:“ int”和“ str”的实例之间不支持“&gt;” - TypeError: '>' not supported between instances of 'int' and 'str' TypeError:&#39;int&#39;和&#39;str&#39;的实例之间不支持&#39;&lt;&#39; - TypeError: '<' not supported between instances of 'int' and 'str' TypeError:“ str”和“ int”的实例之间不支持“&gt;” - TypeError: '>' not supported between instances of 'str' and 'int' DjangoAdmin TypeError:“str”和“int”的实例之间不支持“&lt;” - DjangoAdmin TypeError: '<' not supported between instances of 'str' and 'int' OR STATEMENT TypeError:“str”和“int”的实例之间不支持“&lt;” - OR STATEMENT TypeError: '<' not supported between instances of 'str' and 'int' Python:类型错误:“str”和“int”实例之间不支持“&lt;” - Python: TypeError: '<' not supported between instances of 'str' and 'int'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM