Q. Write a program that ask the user the day number in the year in the range 2 to 365 and ask the first day of the year Sunday or Monday or Tuesday e.t.c . then the program should display the day on the day number that has been input.
You can understand by Watching video :-
Answer :-
d = {"Sunday":1,"Monday":2,"Tuesday":3,"Wednesday":4,"Thursday":5,"Friday":6,"Saturday":7} days = { 1 :"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday"} dic= { } user = int(input("Enter a number between 2 to 365 = ")) day = input("Enter first day of year (Sunday, Monday, Tuesday,Wednesday,Thursday,Friday,Saturday)") first = d[day] for j in range(1,366) : dic[ j ] = first if first == 7 : first = 0 first += 1 a = dic[ user ] print() print(days [ a ])
Output :-
Enter a number between 2 to 365 = 56
Enter first day of year (Sunday, Monday, Tuesday,Wednesday,Thursday,Friday,Saturday)Friday
Thursday
>>>
Enter a number between 2 to 365 = 100
Enter first day of year (Sunday, Monday, Tuesday,Wednesday,Thursday,Friday,Saturday)Monday
Tuesday
>>>
#It can be done more easily
ReplyDeleteday=input("enter first day")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
step1=(dat+7)%7+lis.index(day)
if step1>7:
step1=step1-8
print(lis[step1])
# i think in the last step it should be
Deleteprint(list[step1-1])
Beacuse if u give day num as 1, its giving output as one day ahead
DeleteOur Program is right but if you want other program then
DeleteCorrect code is :-
day=input("enter first day")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
#
step1=(dat+7)%7-1+lis.index(day)
if step1>6:
step1=step1-7
print(lis[step1])
#Is this correct
Wrong program :-
#It can be done more easily
day=input("enter first day")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
step1=(dat+7)%7+lis.index(day)
if step1>7:
step1=step1-8
print(lis[step1])
day=input("Enter first day: ")
Deletedat=int(input("Enter day number: "))
lis=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
Cal = (dat) % 7 + lis.index(day.title())
print(lis[Cal])
#It can be done more easily
ReplyDeleteday=input("enter first day of year ['sun',"mun",'tue','wed','thu','fir','sat']")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
step1=(dat+7)%7+lis.index(day)
if step1>7:
step1=step1-8
print(lis[step1])
Your Program is wrong.
Deleteday=input("enter first day")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
#
step1=(dat+7)%7-1+lis.index(day)
if step1>6:
step1=step1-7
print(lis[step1])
#Is this correct
#It can be done more easily
ReplyDeleteday=input("enter first day of year ['sun',"mun",'tue','wed','thu','fir','sat']")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
step1=(dat+7)%7+lis.index(day)
if step1>7:
step1=step1-8
print(lis[step1])
Your Program is wrong.
Delete#It can be done more easily
ReplyDeleteday=input("enter first day of year ['sun',"mun",'tue','wed','thu','fir','sat']")
dat=int(input("enter day number"))
lis=['sun',"mun",'tue','wed','thu','fir','sat']
step1=(dat+7)%7+lis.index(day)
if step1>7:
step1=step1-8
print(lis[step1]
Path wall your programs are wrong if we put firstday Fri and find the day on day number 22 it showing error
ReplyDeleteOut will come correctly so, please check again.
DeleteEnter a number between 2 to 365 = 22
Enter first day of year (Sunday, Monday, Tuesday,Wednesday,Thursday,Friday,Saturday)Friday
Friday
>>>
Path walla use else so Thai if step1 is not greater than 7
ReplyDeleteOur program is right so, please check again.
Delete# This is so simple and easy try this!!!
ReplyDeletedays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] * 2
firstday = input("Enter the first day of the year: ")
dat = int(input("Enter a number between 2-365: "))
index = days.index(firstday)
print(days[index+(dat % 7)])
# All credits goes to me for uploading here!
# Jinsu
Your program is worng. Correct code :-
Deletedays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] * 2
firstday = input("Enter the first day of the year: ")
dat = int(input("Enter a number between 2-365: "))
index = days.index(firstday)
print(days[ index+(dat % 7) - 1 ])
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )