DEV Community

Cover image for Day 5: Writing our first program in python with home🧡work
aryan015
aryan015

Posted on • Edited on

Day 5: Writing our first program in python with home🧡work

index
In this blog we will cover to take input and print it on the display.

input and output in python

You can take input from the user using input function. Remember input function implicit convert input to string. If you enter number then you cannot perform operations on it.

# you can pass string param to input to display 🧡
import datetime # inbuilt module to play with dates in py
today = datetime.date.today() # datetime.date(2024, 7, 19)
current_year = today.year # 2024
print(current_year)  # This will display the current year (e.g., 2024)
# int converts string to int
DOB = int(input('Enter you age')) # 1998
# calculate your age
print(current_year - DOB) # 26
Enter fullscreen mode Exit fullscreen mode

Thank you

Top comments (0)