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
return volume
def main():
l = 3
w = 4
h = 5
v = get_volume(l, w, h)
print(v)
if __name__ == "__main__":
main()
Refer to Code Example 4-2: What value is passed to the height argument by the call to the get_volume() function?
a. 2
b. 3
c. 4
d. 5
Number 4)
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 Example 4-4: The add() function is called by
a. the main()
b. the arithmetic module
c. function the multiply() function
d. the result statement
Number 5)
Code Example 4-1
def get_username(first, last):
s = first + "." + last
return s.lower()
def main():
first_name = input("Enter your first name:
")
last_name = input("Enter your last name:
")
username = get_username(first_name,
last_name)
print("Your username is: " + username)
if __name__ == "__main__":
main()
Refer to Code Example 4-1: What function is called first when the program runs?
a. get_username()
b.main()
c. input("Enter your first name: ")
d. if __name__ == "__main__"
1) d. import temperature
2) a.from temperature import *
3) d. 5
Explanation:
height is represented by h and value of h=5.
4) c. function the multiply() function
Explanation:
multiply() function calls add() function by passing two parameters .
5) b.main()
Explanation:
main() is the function called first when the program runs
Number 1) Which of the following statements imports a module into the default namespace? a. from...
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...
Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...
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...
(F) Specify the errors of the following code? 1) #include <iostrem> o stream 2) using namespace std; 3) int min() main 4) { 5) double num1 = 5, num2, sum; 6) num2 = 12; 7) sum = numl + num2, 8) cout << "The sum is ">> sum; 9) retrn 0; return 10)}
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...
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...
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:...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
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...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...