make code simpler | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

make code simpler

print("Good evening!") x=2017-int(input("Enter your Birth year")) print("Your age is") print(x) with explanation pls

31st Mar 2017, 5:04 PM
Anneruth M
Anneruth M - avatar
2 Answers
+ 7
Line 1:- prints Good morning,easy enough Line 2:- subtract input from user in int from 2017(which is the current year) and store it in x Line 3:- easy enough Line 4:- prints value of x Line 2 again ---> input("Hello") is used to print hello and then accept input entered by the user int(input("Wow") will print wow, then will store input of the user as an int. 2017-int(input("Wow") will subtract input from 2017
31st Mar 2017, 6:07 PM
Meharban Singh
Meharban Singh - avatar
+ 1
Your code is very straight forward (Just printing a number), so simplicity here is not a target. However why you don't try something like this: print("Good evening!") x = int(input("Enter your Birth year: ")) # Save the input in a variable as it is, in case you need to make some checks on it later print("Your age is:", 2017-x) # Print the string and the age in the same line
31st Mar 2017, 5:30 PM
Moataz El-Ibiary
Moataz El-Ibiary - avatar