Question

Write a function num_day that takes a number in the range of 1 through 7 as...

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

.

.

Homework Answers

Answer #1
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))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
As a small restaurant owner, you are very interested in understanding the demand of your different...
As a small restaurant owner, you are very interested in understanding the demand of your different products. You have been collecting data over the past 11 weeks on the number of fish platter sales that you make each day. You want to run a simulation and you believe that 60% of your fish platter sales for a given week show up on the weekends (evenly split between Friday, Saturday and Sunday) while the remaining 40% are evenly divided across the...
10. (17 pts) A person wants to determine whether the proportion of children born each day...
10. (17 pts) A person wants to determine whether the proportion of children born each day of the week is the same or not in a city; that is, the expected relative frequencies are as follows: Day of Week Relative Frequency Sunday 1/7 Monday 1/7 Tuesday 1/7 Wednesday 1/7 Thursday 1/7 Friday 1/7 Saturday 1/7 The person randomly selected a sample of 500 children and the result is as follows: Day of Week Frequency Sunday 57 Monday 78 Tuesday 74...
The National Highway Traffic Safety Administration reported the percentage of traffic accidents occurring each day of...
The National Highway Traffic Safety Administration reported the percentage of traffic accidents occurring each day of the week. Assume that a sample of 420 accidents provided the following data. Sunday Monday Tuesday Wednesday Thursday Friday Saturday 69 47 54 49 58 69 74 a. Conduct a hypothesis test to determine if the proportion of traffic accidents is the same for each day of the week. What is the p-value? Compute the value of the X2 test statistic (to 3 decimals)....
So, the brewery selected it’s place and now needs to hire folks. After some testing, they...
So, the brewery selected it’s place and now needs to hire folks. After some testing, they expect to have approximately 2,000 customers per week. Since they will be open 7 days a week, they need to hire people to help serve their beer. They know that Friday and Saturday will drive sales. Between these 2 days, they will get 50% of their weekly sales. So, Friday has 25% of sales and Saturday has 25% of the sales. As for Sunday...
MW is a large discount store that operates seven days per week. The store needs the...
MW is a large discount store that operates seven days per week. The store needs the following number of full-time employees working each day of the week. Sunday Monday Tuesday Wednesday Thursday Friday Saturday num of employees 188 88 112 140 136 172 212 Each employee must work five consecutive days each week and then have two days off. For example, any employee who works Sunday through Thursday has Friday and Saturday off. The store currently has a total of...
Refactor the following program to use ArrayList instead of Arrays. You can google "Java ArrayList" or...
Refactor the following program to use ArrayList instead of Arrays. You can google "Java ArrayList" or start with the link below: https://www.thoughtco.com/using-the-arraylist-2034204 import java.util.Scanner; public class DaysOfWeeks { public static void main(String[] args) { String DAY_OF_WEEKS[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; char ch; int n; Scanner scanner = new Scanner(System.in); do { System.out.print("Enter the day of the Week: "); n = scanner.nextInt() - 1; if (n >= 0 && n <= 6) System.out.println("The day of the week is " + DAY_OF_WEEKS[n] + ".");...
d = int(input('Enter the date: ')) m = int(input('Enter the month: ')) y = int(input('Enter the...
d = int(input('Enter the date: ')) m = int(input('Enter the month: ')) y = int(input('Enter the year: ')) if m<3: m = m + 12 y = y - 1 a = (2*m) + (6*(m+1)/10) b = y + (y/4) + (y/400) - (y/100) c = d + a + b + 1 f = c / 7 if f == 0: print ('Sunday') elif f == 1: print ('Monday') elif f == 2: print ('Tuesday') elif f ==3: print...
Records of randomly selected births were obtained and categorised based on the day of the week...
Records of randomly selected births were obtained and categorised based on the day of the week the birth occurred, which is provided below. Since babies are unaware of the tradition work week, it would be reasonable to assume the distribution of births would occur equally on each of the days of the week. At 1% level of significance, test the claim. Can you think of an explanation for the result? Day Sunday Monday Tuesday Wednesday Thursday Friday Saturday Number of...
PHP Question: _____________________________________________ Write the PHP code to list out all of the dates of the...
PHP Question: _____________________________________________ Write the PHP code to list out all of the dates of the current month and assign them to their given days. As an example, for the month of October 2020, the output should look something like this: October 2020       Monday: 5, 12, 19, 26 Tuesday: 6, 13, 20, 27 Wednesday: 7, 14, 21, 28 Thursday: 1, 8, 15, 22, 29 Friday: 2, 9, 16, 23, 30 Saturday: 3, 10, 17, 24, 31 Sunday: 4,...