In: Computer Science
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
Write a testing program named t02.py that tests the function by
asking the user to enter a number
and displaying the output.
A sample run:
Please enter a number between 1 and 7: 7
The number 7 corresponds to Sunday.
Source Code:
functions.py (module)
def num_day(n):
if(n<1 or n>7):
return "Error"
else:
if(n==1):
return
"Monday"
elif(n==2):
return
"Tuesday"
elif(n==3):
return
"Wednesday"
elif(n==4):
return
"Thursday"
elif(n==5):
return
"Friday"
elif(n==6):
return
"Saturday"
elif(n==7):
return
"Sunday"
t02.py (main file)
import functions # importing functions.py module file
num=int(input("Please enter a number between 1 and
7:"))
print("The number",num,"corresponds
to",functions.num_day(num))
Sample input and output: