+ 1

Why when i make this code in my screen a message appears saying you need to enter more input?

birth_year = input ('birth year: ') age = 2024 - birth_year print (age)

2nd Nov 2024, 2:18 AM
Rini Ariani
Rini Ariani - avatar
3 ответов
+ 10
Rini Ariani you are missing the int in the birth_year input # default is a string so convert to integer as int birth_year = int(input ('birth year: ')) age = 2024 - birth_year print(age)
2nd Nov 2024, 3:26 AM
BroFar
BroFar - avatar
+ 7
As @BroFar sir said, in your code `birth_year` is a string, and you can't directly use Arithematic operators on string, it first need to be convert into integer using int().
2nd Nov 2024, 6:28 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 3
Rini, There are two issues. First - when you run your program, a box pops up asking you for the input. In that box, you must answer all the inputs the program requires. It does not ask for input while it's running. You have to provide all answers in advance. That's what the box is for. In your case, in the input box, put the answer to the input(). Which is your year of birth. Then hit submit. The second issue is that your birth_year variable will be a string. All input is a string. So you have to convert that input to an int. BroFar illustrates that in his post. birth_year = int(input ('birth year: ')) Fix the code like that and then enter the year when the box pops up.
2nd Nov 2024, 2:06 PM
Jerry Hobby
Jerry Hobby - avatar