Skip to content Skip to sidebar Skip to footer

Why I Cant Compare Str And Int In Python

This is my code : name = input('What's your name? ') print('Nice to meet you ' + name + '!') age = input('Your age? ') print('So, you are already ' + age + ' years old, ' + name +

Solution 1:

try this : as a solution ; i already update your code to take in considerations the type of the age only an integer

name = input("What's your name? ")
print("Nice to meet you " + name + "!")
while True:
    try:
        age = int(input("Your age? "))
        break
    except Exception as e:
        print("please enter a valid age")
print("So, you are already " + str(age) + " years old, " + name + "!")

if age > 50:
   print ("you are to old thx ")

else:
   print ("nice age using your apportunity ")

Post a Comment for "Why I Cant Compare Str And Int In Python"