54.3k views
3 votes
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?

User Coolbreeze
by
5.1k points

1 Answer

2 votes

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.

User JeffP
by
5.3k points