150k views
9 votes
Q3. The 1st day of 2022 was Saturday, write a program to input any day number within the month of January and print which day was it. Also check whether the day number entered is a valid date or not.

For example, Input:
Enter day number: 20 Output: Thursday
Input:
Enter day number: 30
Output: Sunday Input:
Enter day number: 34 Output: Invalid day number

User Jette
by
4.0k points

2 Answers

8 votes

Let's see


\tt d=int(input(


\tt D=\left\{1:


\tt if\:d<=0\:and\:d>31:


\quad\tt print(


\tt else:


\quad\tt for\:i\:in\:D:


\quad\quad\tt if\:i==d:


\quad\quad\quad\tt print(D\left[i\right])

Q3. The 1st day of 2022 was Saturday, write a program to input any day number within-example-1
User Clearscreen
by
4.5k points
10 votes

Answer: Here's the code if you solve it using python

Step-by-step explanation:

day="Saturday"

date=int(input("Enter the day number: "))

if (date<=0) or (date>31):

print("Invalid day number")

else:

if date%7==1:

day="Saturday"

elif date%7==2:

day="Sunday"

elif date%7==3:

day="Monday"

elif date%7==4:

day="Tuesday"

elif date%7==5:

day="Wednesday"

elif date%7==6:

day="Thursday"

elif date%7==0:

day="Friday"

print(day)

User Arsanyf
by
4.3k points