223k views
4 votes
Please tell me what the mistake in this python code is ?

Birth_Year = input("What is your birth year")

if Birth_Year <= 2000:
print("Wow youre old")

if Birth_Year >= 1999:
print("lol youre still a baby")

User Diving
by
8.3k points

2 Answers

1 vote

Answer:

Set the variable as an integer

Step-by-step explanation:

You will need to set the question as an integer:

Birth_year = int(input("What is your birth year"))

This will ensure that the number placed in will become an integer, instead of a string

User Krishna Thota
by
7.6k points
6 votes

The mistake in this Python code is that the input function returns a string, not an integer. Therefore, when you compare the value entered by the user to an integer (2000 or 1999), it will result in a TypeError.

To fix this, you can convert the input to an integer using the int() function. Here's the corrected code:

Birth_Year = int(input("What is your birth year? "))

if Birth_Year <= 2000:

print("Wow, you're old.")

if Birth_Year >= 1999:

print("lol, you're still a baby.")

Note that I've also added indentation to the print statements so they are executed only when the condition is true.

User Xavier Decoster
by
7.7k points