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
8.0k 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
7.9k points

Related questions

2 answers
4 votes
140k views
1 answer
2 votes
80.9k views
asked Feb 26, 2021 192k views
Shadowbob asked Feb 26, 2021
by Shadowbob
8.2k points
1 answer
4 votes
192k views