Header Ads Widget

Python program to input week number and print week day

 Python program to input week number and print week day

Given a week number , write a program to print the week day i.e if week number is 1 then week day is Monday , if 2 then Tuesday and so on .

Method 1 : Simply by using if-else 

Method 2 : By using Dictionary 

Sample input:

5

Sample output:

Friday

 Python program to input week number and print week day

The objective of the code is print the week day based on the week number .

Method 1 :

Code(Python):-

print("Enter week number")
n=int(input())
if(n==1):
print("Monday")
elif(n==2):
print("Tuesday")
elif(n==3):
print("Wednesday")
elif(n==4):
print("Thursday")
elif(n==5):
print("Friday")
elif(n==6):
print("Saturday")
elif(n==7):
print("Sunday")
else:
print("Invalid input")

Method 2:

print("Enter week number")
n=int(input())
dic={1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday",7:"Sunday"};
if(n>=1 and n<=7):
print(dic[n])
else:
print("Invalid input")

Output:-

Enter week day
5
Friday

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

 

Post a Comment

0 Comments