Write a function num_day that takes a number in the range of 1 through 7 as a parameter and
returns a string representing the corresponding day of the week, where 1=Monday, 2 =Tuesday,
3= Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday.
The function should return the string "Error" if the parameter is that is outside the range of 1 through 7.
You may assume that the parameter will be only numbers.
Save the function in a PyDev library module named functions.py
A sample run:
Please enter a number between 1 and 7:7
The number 7 corresponds to Sunday
Or
Please enter a number between 1 and 7:9
The number 9 corresponds to Error
.
.
def num_day(n): lst = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] if(n>=1 and n<=7): return lst[n-1] else: return "Error" # Testing n = eval(input("Please enter a number between 1 and 7:")) print("The number",n,"corresponds to",num_day(n))
Get Answers For Free
Most questions answered within 1 hours.