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

>>>



16 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. #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])

    ReplyDelete
    Replies
    1. # i think in the last step it should be
      print(list[step1-1])

      Delete
    2. Beacuse if u give day num as 1, its giving output as one day ahead

      Delete
    3. Our Program is right but if you want other program then

      Correct 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])

      Delete
    4. day=input("Enter first day: ")
      dat=int(input("Enter day number: "))
      lis=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]

      Cal = (dat) % 7 + lis.index(day.title())

      print(lis[Cal])

      Delete
  2. #It can be done more easily
    day=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])

    ReplyDelete
    Replies
    1. Your Program is wrong.


      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

      Delete
  3. #It can be done more easily
    day=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])

    ReplyDelete
  4. #It can be done more easily
    day=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]

    ReplyDelete
  5. Path wall your programs are wrong if we put firstday Fri and find the day on day number 22 it showing error

    ReplyDelete
    Replies
    1. Out will come correctly so, please check again.

      Enter a number between 2 to 365 = 22
      Enter first day of year (Sunday, Monday, Tuesday,Wednesday,Thursday,Friday,Saturday)Friday

      Friday
      >>>

      Delete
  6. Path walla use else so Thai if step1 is not greater than 7

    ReplyDelete
    Replies
    1. Our program is right so, please check again.

      Delete
  7. # This is so simple and easy try this!!!
    days = ["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

    ReplyDelete
    Replies
    1. Your program is worng. Correct code :-

      days = ["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 ])

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post