Python help! Any help is appreciated, thank you!
Fill in the missing function, monthString(), in the program. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return "January". If the parameter is 2, your function should return out "February", etc.
| def monthString(monthNum): | |
| """ | |
| Takes as input a number, monthNum, and | |
| returns the corresponding month name as a string. | |
| Example: monthString(1) returns "January". | |
| Assumes that input is an integer ranging from 1 to 12 | |
| """ | |
| monthString = "" | |
| ################################### | |
| ### FILL IN YOUR CODE HERE ### | |
| ### Other than your name above, ### | |
| ### this is the only section ### | |
| ### you change in this program. ### | |
| ################################### | |
| return(monthString) | |
| def main(): | |
| n = int(input('Enter the number of the month: ')) | |
| mString = monthString(n) | |
| print('The month is', mString) | |
| #Allow script to be run directly: | |
| if __name__ == "__main__": | |
| main() |
CODE
def monthString(monthNum):
"""
Takes as input a number, monthNum, and
returns the corresponding month name as a string.
Example: monthString(1) returns "January".
Assumes that input is an integer ranging from 1 to 12
"""
switcher = {
1: "January",
2: "February",
3: "March",
4: "April",
5: "May",
6: "June",
7: "July",
8: "August",
9: "September",
10: "October",
11: "November",
12: "December",
}
monthString = switcher.get(monthNum, "")
return(monthString)
def main():
n = int(input('Enter the number of the month: '))
mString = monthString(n)
print('The month is', mString)
#Allow script to be run directly:
if __name__ == "__main__":
main()
![[GCC 4.8.2] on linux def monthString (monthNum): Enter the number of the month: 4 1 The month is April и 2 Takes as input a n](http://img.homeworklib.com/questions/c6e50db0-a61b-11ea-85b0-c5b703c5023f.png?x-oss-process=image/resize,w_560)
Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the...
Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...
Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import * b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2): volume = width * height * length...
Higher or Lower Game(use python3 to solve this) You will build a game that asks the user to guess a random number between 1-100. Your program will do the following: Ensure user input is valid (users can only guess integers) Provide a hint for each valid guess: the answer is either going to be higher or lower than the guess Solution import random # Define a function that asks the user for input and DOESN'T QUIT until the user...
Write a program in python that lets the user play the game Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. 2 corresponds to paper, and 3 corresponds to scissors. To set up the random number library, write the following at the top of your code: import random random.seed(300) Use...
I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code...
Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs. txt, articles.txt, and prepositions.txt. (HINT: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list...
average_value_in_file / Python 3.x: Your assistance is appreciated, thank you! Write a function named average_value_in_file that accepts a file name as a parameter and reads that file, assumed to be full of numbers, and returns the average (mean) of the numbers in that file. The parameter, filename, gives the name of a file that contains a list of numbers, one per line. You may assume that the file exists and follows the proper format. For example, if a file named...
In Python, revise this code. define convert(s): """ Takes a hex string as input. Returns decimal equivalent. """ total = 0 for c in s total = total * 16 ascii = ord(c if ord('0) <= ascii <= ord('9'): #It's a decimal number, and return it as decimal: total = total+ascii - ord('0') elif ord('A") <= ascii <= ord('F'): #It's a hex number between 10 and 15, convert and return: total = total + ascii - ord('A') + 10 else...
Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...
My module page is correct but I don't believe I am using the main() function properly. One of my .py files is supposed to contain my definitions, which is the module file. My second .py file is supposed to properly call a main function that does what my program asks it to: First name, last name, age, and respond based off of input. For some reason I am struggling with using the main() function so that my program works. Any...