Hey Guy’s, Welcome to PracticeHouse. The house is full of exercises program to increase our skill level up.
In this post I am going to share our first exercise program for python is – Create a program that takes the name and the age from the user as input and then send them a message that which year they will be 100 years old.
pretty cool !!! isn’t it. Let’s see our code for the program to take user input and calculate their age.
okay let’s see the code first if you are a beginner then don’t worry down there i will explain the code also and if you are familiar with python code then you good to go.
Sample Code:
1 2 3 4 5 6 7 8 9 10 11 |
import datetime name = input("Please tell us your name : ") age = int(input("Please enter your age : ")) toBe100 = 100 - age today = datetime.datetime.now() year = (today.year) year += toBe100 print(f"Hey {name} , You will be 100 years old in this {year}") |
Here is the sample output :
1 2 3 4 5 |
PS D:\Alif\Python\Project001> python .\exercise1.py Please tell us your name : Alien Please enter your age : 25 Hey Alien , You will be 100 years old in the year of 2094 PS D:\Alif\Python\Project001> |
Explanation :
Okay folks, Let me explain this program if you didn’t understand. it’s a very simple program in python.
first of all, you can see that i saved this in a file called exercise1.py So .py is the file extension for the python script file.
To run a python script in a shell or CLI you have to open the CLI into that respective folder or you can navigate through CLI into that folder then use python and then your filename.
Then we use input()
function to take user input. So by default, it returns us String.
To Convert the string into integer we used int()
function for our age variable.
To get the current date and time we import a library called datetime by using import datetime
. then we use datetime.datetime.now()
function to get the current date and store into a variable called today. then use today.year
to get the current year.
then we just did a small calculate when the user will be 100 years old.
Then in python, we use print()
function to printout something to our console.
That’s it.
So if you have any other way to show us. you are most welcome to share your code down there.

Md Arifur Rahman, Nickname is Alif.
Leave a Reply