Question

In: Computer Science

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
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.

Solutions

Expert Solution

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:


Related Solutions

Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
Write a JAVA program read a number within the range of 1 through 1000 to display...
Write a JAVA program read a number within the range of 1 through 1000 to display the Roman numeral version of that number. Include screenshot of the output
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the product of two prime numbers ? and ? and returns the tuple ( ?, ? ) where ?≤? . Example: ????????(22)=(2,11) Example: ????????(3605282209)=(59447,60647) This problem has a time-out limit of 1 second and a memory limit of 1MB. The number ? in all test-cases will satisfy 4≤?≤800000000000000 For example: Test Result print(factorMe(22)) (2, 11) print(factorMe(3605282209)) (59447, 60647)
Write a function DIVISORS in MIPS. This function takes a positive number from the register a0...
Write a function DIVISORS in MIPS. This function takes a positive number from the register a0 and prints in a column all of its divisors including 1 and the number itself. Don't forget that printing a number and printing a character requires two different system calls. Here is an example. If the number in a0 is 6 the following output appears: 1 2 3 6
Match a student number: Write a function MatchStudentNumber that takes a student number from the StudentNumber...
Match a student number: Write a function MatchStudentNumber that takes a student number from the StudentNumber column in the reference table and determine if there is a match with a student number from the StudentNumber column in the second table. The output is a logical flag that is true if at least one match was found, and integer array that points to rows in table where a match occurred. Note that the function should find all matches. function [iflag, matchPosition]...
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT