+ 1

Any efficient solution for this problem ?

The day corresponding to the first day of a month and a date is given as input. The program must print the day of the date . I/p : MON 10 o/p : WED Exp: If the first day of the month is Monday and the day on 10th of that month is on Wednesday.

9th Oct 2020, 10:51 AM
Levi
Levi - avatar
8 ответов
+ 8
Mndm , here is a short version of rotating a list. "d" is the number to rotate the items from the iterable "arr". pos number is shift left, neg number is shift right. # rotate list def rotate(arr, d): return arr[d:] + arr[:d]
9th Oct 2020, 2:45 PM
Lothar
Lothar - avatar
+ 8
Here is my version: (it uses a list that will be shifted once, so it avoids iterating through date) day = input() date = int(input()) days = [ 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'] shift = days.index(day) arr = days[shift:] + days[:shift] print(arr[(date % 7) -1])
9th Oct 2020, 4:00 PM
Lothar
Lothar - avatar
+ 5
Please show us your attempt first, before we can help you. put your try in playground and link it here. Thanks!
9th Oct 2020, 11:06 AM
Lothar
Lothar - avatar
+ 2
I give you hints 1. Make a tuple of 7 elements having Days of Week in sequence (important) 2. Find the First day in tuple and store it's index in a variable , suppose x.... 3. Then make a loop that iterate over that tuple starting from index (x) and stop when we reaches the date...
9th Oct 2020, 11:16 AM
Abhay
Abhay - avatar
+ 1
Do you have any idea written as some lines of code?
9th Oct 2020, 11:06 AM
Shadoff
Shadoff - avatar
+ 1
Lothar Avalon https://code.sololearn.com/cY69UFgs3XMX/?ref=app I have attached the code. But I can't get the output. Here I iterated through the list 'days'. Any simple code for list rotation ?? Thank you !!
9th Oct 2020, 11:23 AM
Levi
Levi - avatar
+ 1
day = input().strip() date = int(input()) days = [ 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'] x = days.index(day) y = x for i in range(date): y+=1 if days[y]=='SUN': y=0 print(days[y-1])
9th Oct 2020, 12:09 PM
Abhay
Abhay - avatar
9th Oct 2020, 3:23 PM
Shadoff
Shadoff - avatar