Python program to show when you are 100 yrs old


               
                   Hello. In this post, we see the program of python program that asks the user to enter their name and their age and it prints out a message addressed to them that tells them the year that they will turn 100 years old. This is a very simple and compact code, to assign in python features.

Program:

name=input("What is your name:")
age=int(input("How old are you:"))
year=str((2017-age)+100)
print( name, "You will be 100 years old in the year", year)

Explanation:
                  This is the second code for us to write and run the code in python. I explain this code because this code is a little bit complicated. I explain this code line by line, so let's start ...

1.name=input("What is your name:")
In this line, we use the "input" keyword to get input from the user i.e. user name and stored into the "name" variable. The string which is used in the double quote is instruction for the user.

2.age=int(input("How old are you:"))
In the first line, we did not use any datatype line int or float or char but in this line, we use int datatype to accept integer value as age from the user and store this age into the variable age.

3.year=str((2017-age)+100)
To display the year, when the user is 100 years old. Here we forcefully convert int datatype into string datatype. So we use str. year=((2017-age)+100) this is correct as per condition but not per logic, so we use year=str((2017-age)+100).

4.print( name, "You will be 100 years old in the year", year)
This is a simple print statement to print a message with name and year. To display the message we use a double or single quote and to display the value which is stored in the variable and assign variable in print statement we did not use double or single quote. The output is like,

Output:

What is your name: Amit
How old are you:19
Amit You will be 100 years old in the year 2098
If you have any doubt then write it in a comment.


Python program to show when you are 100 yrs old Python program to show when you are 100 yrs old Reviewed by Amit Waghmare on November 07, 2019 Rating: 5

No comments: