Python program to implement & use a switch case statement to make decisions
ADVERTISEMENTS
Python program to implement & use a switch case statement (Replacement) to make decisions, In this program you will understand how to implement your own function to check cases as a switch case statement.
- before implementing this function you need to know unlike other languages python does not exist own switch case statement to check cases step-by-step.
- So we can implement own a function to check cases, It will be worked as a switch case statement
Let us understand this statement through a python example:
# Python program to implement & use the switch case statement
def switch(argument):
# Switcher is dictionary data type here
switcher = {
1: "Hi\nIt's sunday on today, It's the week-off day.\n",
2: "Hi\nIt's monday on today, It's the working day.\n",
3: "Hi\nIt's tuesday on today, It's the working day.\n",
4: "Hi\nIt's wednesday on today, It's the working day.\n",
5: "Hi\nIt's thursday on today, It's the working day.\n",
6: "Hi\nIt's friday on today, It's the working day.\n",
7: "Hi\nIt's saturday on today, It's the week-off day.\n"
}
# the get() will be return value of dictionary
return switcher.get(argument, "Sorry, You entered the wrong week number, Kindly try again\n")
print("Enter a week number among 1 to 7\n")
w = int(input())
if (w):
print(switch(w))
else:
print("Sorry didn't entered any week number!\n")
Output
Enter a week number among 1 to 7
4
Hi
It's wednesday on today, It's the working day.