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

  Integration of mnch commodities supply chain management

Objective of the study is to examine the outcome of integration of logistic and supply chain management of MNCH commodities on service delivery, specific objectives have been set to achieve the aim of the study.

  How would you represent the game as a collection of objects

How would you represent the game as a collection of objects? What entities do you think are in the game that should be modeled as an object?

  Write a client pingprogram in python

Write a client pingprogram in Python. Your client will send a simple ping message to a server, receive a correspondingpong message back.

  How you might utilize the given as a programmer

Research is key when becoming an effective programmer. Locate a useful resource on the web for programming in Python and discuss what it provides.

  Compare crimes rates in different cities

Use the following dataset 'Crime in Major Cites' to compare crimes rates in different cities for the years listed in the dataset. Is there an obvious trend

  Program for simulating a supermarket self-service checkout

ITECH1400 - Foundations of Programming - Design and model two classes: Product and CheckoutRegister and Create an activity chart which describes the behaviour

  Write a python program that reads in academic achievements

Write a Python program that reads in the academic achievements of three international applicants and determines which one is the best candidate.

  Simulates a simple money manager

ITECH1400 – Foundations of Programming - Money Manager - Creating an application that uses a GUI that simulates a simple money manager

  Calculates the course average as the sum of the exams

CIS101 Calculates the Course Average as the sum of the exams divided by 4 and stores the result in a new variable named courseAverage.

  Convert hexadecimal 4c to decimal

Your first objective in this lesson is to understand binary numbers and hexadecimal numbers. Then, you must learn how to quickly and accurately convert between decimal numbers, binary numbers

  Write a program using the following python functions

You are required to write the following Python functions. Make sure you understand where each function fits into the system described above.

  Programmer does not have to use the def statement

Unlike Z+-, the programmer does not have to use the DEF statement to create a variable. Instead, the programmer can simply use the variable. The first use of the variable creates it and initializes it to 0.

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