Where is the problem please tell me 🥺 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where is the problem please tell me 🥺

age=input("what is your age:") B=2024-age print(B)

24th Mar 2024, 4:56 AM
sayem ahmed
sayem ahmed - avatar
4 Answers
+ 4
# inputs for code cosch without text age = int(input())
24th Mar 2024, 7:07 AM
JaScript
JaScript - avatar
+ 2
Vz
25th Mar 2024, 11:56 AM
Saima
Saima - avatar
+ 1
age = input("What is your age: ") B = 2024 + int(age) print(B) In Line 2 you need to convert your input into integer before adding. or you can simply change first line to age = int(input("What is your age: "))
24th Mar 2024, 4:59 AM
Ayush
Ayush - avatar
+ 1
age is an string when you try to operate with an integer, you have to use int() function (or float() for a decimal number) to convert it into a number and operate with that, you can make it directly conver into an integer with int(input()). you cannot operate mathematically with strings, but you can still "+" to join two of them, for example, when printing "B", you can use print("Then, your birth year is: "+str(B)) to make it cooler and more user friendly. if you dont want to convert "B" into a string (using str()), you can use print("text", B) for printing two separate statements on a single line. you can use this as much times as you want at the same print() function
25th Mar 2024, 9:24 PM
Borjo
Borjo - avatar