+ 2

Pls help me with my code

Create a Python program that accepts a day of the week, as well as a value that indicates the number of days to be shifted. As a result, the program should output the day of the week resulting from the shift. that is the task. I really tried my best however, I'm just starting and got stuck on the last part. How do I have to change my code in order to receive the correct week day as an answer and not just the result of the equation; be it -2 or any other number? https://code.sololearn.com/ce0G5q8clwll

25th Oct 2021, 12:11 PM
Jonas Treusch
Jonas Treusch - avatar
2 Antworten
+ 2
This question is solved ☑️✅✔️
26th Oct 2021, 12:54 AM
Rishi
Rishi - avatar
+ 5
Have an array with the week days as elements days=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"," Sunday"] Then get the input day in a variable "day" number to be shifted in a variable, say "shift". Then find the index of "day" in daya array and add the variable shift to the index and modulus it by max array index(6). It's like the below implementation pos=find(days, day) pos=(pos+shift)%6 Now output the element at position pos print(days[pos]) Try this and tell me if it worked. Feel free to ask any doubt you have in my answer. All the best =)
25th Oct 2021, 12:20 PM
Rishi
Rishi - avatar