PEP 8 and naming
You named your variables according to PEP 8 and also gave them reasonable names, with some exceptions:
list
. It overrides a built-in type and does not convey what it contains. Consider renaming it WEEKDAYS
as it represents a global constant.
give_day
actually reads the current day from the user, so current_day
would be more appropriate
- ... and so would be
current_day_index
instead of index_give_day
.
Also note that PEP 8 wants you to put a space after a comma in e.g. list definitions.
Input validation
You never validate the input of the user. If they enter an invalid day, the program will terminate with a ValueError
.
Know your requirements
Your title only mentions returning the next day, but the program also calculates the previous day. Is this necessary?
Use functions
Currently your code only works as an isolated script. There is no reusability.
Consider putting the code that returns the next item of an arbitrary list into a function
Putting it together
#! /usr/bin/env python3
from os import linesep
from typing import Any
WEEKDAYS = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
]
def neighbors(item: Any, items: list[Any]) -> tuple[Any, Any]:
"""Return the predecessor and successor entry
for the item of the given list.
"""
return (
items[(index := items.index(item)) - 1],
items[(index + 1) % len(items)]
)
def main() -> None:
"""Run main program."""
current_day = input('Enter the day : ')
try:
previous_day, next_day = neighbors(current_day, WEEKDAYS)
except ValueError:
print('Invalid weekday:', current_day)
else:
print(previous_day, next_day, sep=linesep)
if __name__ == '__main__':
main()