简体   繁体   中英

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

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM