What will be displayed after the code runs

Assignment Help Python Programming
Reference no: EM132330144

Question 1

Which statement would you use to call the print_name() function from a module named address that has been imported with this statement?

import address as a

a. print_name(name)

b. global.print_name(name)

c. a.print_name(name)

d. address.print_name(name)

Question 2

To call a function with named arguments, you code the

a. name of each argument, an equals sign, and the value or variable that's being passed

b. values that you're passing in the same sequence that the names are defined in the function

c. values that you're passing at the beginning of the function call

d. values that you're passing at the end of the function call, followed by the names that correspond with the values

Question 3

The default namespace for a module is

a. the first letter of the module name

b. the same as the name of the module

c. the global namespace

d. the name of the module followed by _default

Question 4

A file that contains reusable code is called a

a. namespace

b. hierarchy chart

c. module

d. function

Question 5

Code Example 4-3

main program:

import arithmetic as a

def main():

num1 = 5

num2 = 6

result = a.add(num1, num2)

print("The sum is", result)

if __name__ == "__main__":

main()

arithmetic module:

def add(x = 4, y = 2):

z = x + y

return z

Refer to Code Example 4-3: What will be displayed after the code runs?

a. The sum is 11

b. The sum is 6

c. The sum is 17

d. Nothing, the code causes an error

Question 6

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 multiply() function

b. the arithmetic module

c. the result statement

d. the main() function

Question 7

Assuming the random module has been imported into its default namespace, which of the following could be used to simulate a coin toss where 0 = heads and 1 = tails?

a. number = random.randint(0, 1)

b. number = random.random()

c. number = random.coin()

d. number = random.randint(0, 2)

Question 8

A global variable

a. is defined inside the main() function

b. cannot be modified inside a function

c. cannot be accessed from within a function

d. is defined outside of all functions

Question 9

Assuming the random module has been imported into its default namespace, which of the following could be used to generate a random even integer from 2 through 200?

a. number = random.randrange(2, 202, 2)

b. number = random.randint(2, 200, 2)

c. number = random(1, 100) * 2

d. number = random.randrange(2, 200, 2)

Question 10

Which of the following is not true of hierarchy charts?

a. Function names should start with a verb and indicate what the functions do.

b. Each function should do only what is related to the function name.

c. The top level box should be for the main() function.

d. Related functions should be combined into a single function.

Question 11

Code Example 4-3

main program:

import arithmetic as a

def main():

num1 = 5

num2 = 6

result = a.add(num1, num2)

print("The sum is", result)

if __name__ == "__main__":

main()

arithmetic module:

def add(x = 4, y = 2):

z = x + y

return z

Refer to Code Example 4-3: What values are in x and y after the code runs?

a. 5, 6

b. 9, 8

c. 4, 2

d. 20, 12

Question 12

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: If the user enters 'Lopez' for the first prompt in main() and 'Maria' for the second prompt, what will display?

a. Maria.Lopez

b. Lopez.Maria

c. lopez.maria

d. maria.lopez

Question 13

A local variable is defined

a. inside a function

b. inside the main() function

c. inside an if statement

d. outside of all functions

Question 14

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 arguments are defined by the get_username() function?

a. username

b. first_name, last_name

c. s, first, last

d. first, last

Question 15

Which of the following statements imports a module into the global namespace?

a. from temperature import *

b. import temperature as temp

c. import temperature

d. import temperature as global

Question 16

The best way to call the main() function of a program is to code

a. an if statement that calls the main() function only if the function exists

b. a while statement that calls the main() function in each loop

c. an if statement that calls the main() function only if the current module is the main module

d. main()

Question 17

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: If you add the following code to the end of the main() method, what does it print to the console?

print(get_volume(10, 2))

a. 20

b. 60

c. Nothing, it causes an error

d. 40

Question 18

If you import two modules into the global namespace and each has a function named get_value(),

a. an exception occurs

b. a name collision occurs

c. the program crashes

d. an error occur

Question 19

Which of the following statements imports a module into the default namespace?

a. from temperature import *

b. import temperature as temp

c. import temperature as t

d. import temperature

Question 20

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. if __name__ == "__main__"

b. input("Enter your first name: ")

c. main()

d. get_username()

Reference no: EM132330144

Questions Cloud

What the results to each party would be : Create a hypothetical scenario in which an innocent, routine interaction between a citizen in a public place and the police could result in a continuing.
Write a while loop that keeps printing the menu selection : An inventory of the media store is displayed when option 1 is selected. We can see the references, media type, title and price of each item.
Display the number of seats sold and the revenue collected : Python program that obtains the number of Reserved Seating tickets that have been sold for a recent event and totals their revenue.
What is the more effective method of delivery a nebuliser : 92440 Evidence for Nursing Assignment, University of Technology Sydney, Australia. What is the more effective method of delivery- a nebuliser or a spacer
What will be displayed after the code runs : Assuming the random module has been imported into its default namespace, which of the following could be used to generate a random even integer.
What are the specific aims and purposes of the criminal law : What are the specific aims and purposes of the criminal law? To what extent does the criminal law control behavior? What kinds of activities should be labeled.
Why do you think the societies needed creation stories : How are the creation stories of the Mayas, contained in the Popol Vuh, and of the ancient Hebrews, contained in the Genesis story, similar.
How religion aligns with the theories and features : In this assignment you will pretend you are in control and create a new religion. You will name it, discuss its deity(s), discuss its theory, features.
Brief description of your chosen workplace : IND301A: Industry Consulting Project Assessment - Work integrated report, Laureate International Universities, Australia. Brief description of chosen workplace

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd