Write a python program to input week number and print week day
In this post, you will learn how to write a Python program to input a week number and print the week day. For example, if the user enters 1, that implies it is Monday, and if the user enters 7, then the output should be Saturday.
To implement this, we need to take input from the user and store it in a variable. After taking input from the user, we have to compare that number with 1 to 7, or we can say, compare that number with a day of the week. So the logic goes like– if the number is equal to 1, then it is Monday, if the number is 2, then it is Tuesday; like that, we have to compare with each day of the week.
Python Program
The given Python program implements the above logic and prints the week day.
# Python program to input week number and print week day
weekday = int(input("Enter weekday number (1-7) : "))
if weekday == 1 :
print("\nMonday");
elif weekday == 2 :
print("\nTuesday")
elif(weekday == 3) :
print("\nWednesday")
elif(weekday == 4) :
print("\nThursday")
elif(weekday == 5) :
print("\nFriday")
elif(weekday == 6) :
print("\nSaturday")
elif (weekday == 7) :
print("\nSunday")
else :
print("\nPlease enter any weekday number (1-7)")
Output1:
Enter weekday number (1-7) : 5
Friday
Output2:
Enter weekday number (1-7) : 2
Tuesday
Related Articles
Print first 10 natural numbers using while loop in PythonPython program to convert month name to a number of days
Python program to calculate number of days between two dates
Sum of digits of a number in Python
Python program to calculate the average of numbers in a given list
Find element in list Python
Python program to check leap year
Python program to reverse a string
Pascal triangle pattern in Python
Permutation and Combination in Python
Check if two strings are anagrams Python
Convert Excel to CSV Python Pandas
Python take screenshot of specific window
Read data from excel file using Python Pandas
Quick Introduction to Python Pandas
Python requests GET method
Python Convert XML to CSV
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python raise keyword