For Edhesive Assignment 3: Chatbot
I keep getting an error in my if statement when I have
age= input(“How old are you?”)
print(str(age) + “ is a good age.”)
if (age >= 17):
What am I doing wrong?

Answer :

Cytokine

When you use the input function, the variable you assign it to is automatically a string unless you cast it to another type. In your code, age is a string and strings cannot be greater than or equal to 17. This is what you need to do:

age = int(input("How old are you? "))

print(str(age) + " is a good age.")

if (age >= 17):

   #do whatever.

Other Questions