![](/img/trans.png)
[英]TypeError: '<' not supported between instances of 'str' and 'int' after converting string to float
[英]TypeError: '>' not supported between instances of 'str' and 'int' but I made the string an Interger
我有一個我似乎無法修復的非常令人沮喪的錯誤,它告訴我字符串和整數不支持“<”,但我確保我使用 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")
我失去了想法,我應該改變什么?
int(number_pick)
此強制轉換返回轉換結果,但您並未將其存儲在任何地方。
number_pick = int(number_pick)
您可能還想添加一些錯誤檢查:
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.