Microsoft Online Assessment (OA) - Day of week that is K days later

Given current day as day of the week and an integer K, the task is to find the day of the week after K days.

Example 1:

Input:

day = “Monday”

K = 3

Output: Thursday

Example 2:

Input:

day = “Tuesday”

K = 101

Output: Friday

Try it yourself

Implementation

1def day_of_week(day: str, k: int) -> str:
2    days = [
3        'Monday',
4        'Tuesday',
5        'Wednesday',
6        'Thursday',
7        'Friday',
8        'Saturday',
9        'Sunday',
10    ]
11    index = 0
12    for i in range(len(days)):
13        if days[i] == day:
14            index = i
15    return days[(index + k) % 7]
16
17if __name__ == '__main__':
18    day = input()
19    k = int(input())
20    res = day_of_week(day, k)
21    print(res)
22