Python Coding Exam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

In the following line of Python code, what is the argument to the input function? user_status = input("How are you today?")

"How are you today?"

Which of the following Python operators finds the remainder from division?

%

What is displayed with the following code is run? my_balance = 100 my_balance += 2 * 3 + 1 print (my_balance)

107

Given the following line of code: labor_hours = float(input("How many labor hours were worked to produce the output?")) Sequence the following items in the order they would occur while this line of code is executed: The user enters the number of hours The user's entry is converted to a floating point number The user's entry is received by the program as a string The argument to the input() function is printed to the screen The floating point number value of the user's entry is assigned to labor_hours

2, 4, 3, 1, 5

If the last element in my list has an index of 20, how many items are in the list?

21

What would be printed by the following code? products = 3 purchase_orders = [2, 3, 5, 9, 25, 18, 2, 4, 9] for x, an_order in enumerate(purchase_orders): if x == 3: data = an_order / products print(data)

3

What would be printed by the following loop? i = 20 for x in range(0, 15, 5): i -= x print(i)

5

The condition(s) of a loop appear directly before the __________________.

:

Which symbol is used to assign a value to a variable in Python?

=

Which of the following statements is true about comments in coding? A: Comments are a form of communication with other programmers (including yourself) B: An inline comment in Python begins with ''' and ends automatically at the end of that line C: A block comment in Python begins and ends with # D: Comments are a form of communication with the user of the program

A

Which of the following statements would result in the value of the variable my_num being the same as the value of my_num squared? A: All of these answers B: my_num *= my_num C: my_num = my_num**2 D: my_num = my_num * my_num

A

Which of the following would be a correct if statement line in Python? A: if i == 7: B: if i = 7: C: if i == 7 then: D: if i = 7 then

A

Based on the conventions we are using for variable names, which of the following is a good variable name for labor hours in the labor productivity calculation? A: Labor_Hours B: labor_hours C: LH D: all_the_hours_worked_this_period

B

Which of the following Python conditions would be True? A: "A rose" == "a rose" B: "A rose" != "a rose" C: "a rose" =! "A rose" D: "A rose" = "a rose"

B

Which of the following are considered comparison operators? A: if, elif, else B: >, <, >=, <= C: +, -, *, / D: and, or

B

Which of the following if statement conditions would be True only when hours_worked complied with the business rules (had a value between 1 and 60 inclusive)? Assume that hours_worked is an integer variable. A: if hours_worked >=0 and hours_worked < 60 B: if hours_worked < 61 and hours_worked > 0: C: if hours_worked <= 61 or hours_worked > 1: D: if hours_worked > 0 or hours_worked < 61:

B

Consider our coding standards and the algorithm you used to develop your labor productivity program. Which of the following items does NOT need to appear in your program file before calculating the labor productivity? A: The preamble block comment B: An input statement asking the user for the sales C: Intialize the variable for labor productivity to a value of 0 D: Code to convert the sales and labor hour variables to type float

C

Given the Python code: user_feedback = ________________ If this text replaced the _____________, the variable user_feedback would be a string. A: hey_hey_hey B: 12.3 C: "hey_hey_hey" D: 123

C

Which of the following is NOT true when interpreting the results of Net Present Value calculations in capital budgeting? A: When choosing between multiple projects, the one with the higher positive NPV should be accepted B: Projects with a positive NPV should be accepted C: Projects with a negative NPV should be accepted D: None of these

C

Which of the following is the correct way to test if i is NOT equal to 5? A: i > 5 B: i # 5 C: i != 5 D: i !== 5

C

Which of the following is true when calculating productivity? A: Productivity is calculated by dividing the total inputs by the total outputs B: Inputs must always be expressed in hours C: It is important to specify the unit of measure used for inputs and outputs D: Outputs must always be expressed in dollars

C

Which of the following does not describe a part of computational thinking in business? A: developing a strategy to solve the problem B: expressing the solution to a problem with code C: understanding the problem D: a fancy way of saying coding

D

Which of the following would display the number 9 as output? A: print(Math.Round(9.2)) B: print(ceil(9.2)) C: print(Round(9.2)) D: print(round(9.2))

D

In Python, numbers with decimal places like -12.38 or 3.14159 are stored as type float. True or False?

True

To confirm that your program is working correctly, test cases should check each branch of the if / elif / else blocks in your code. True or False?

True

The body of the loop (the code that executes each time the loop runs) can contain _____________ statements.

any number of

Which of the following methods adds an item to the end of a list?

append()

The block of code to be executed when an if or elif condition is true MUST:

be indented

In a for loop, line 2 is indented...

because it takes its orders from line 1

A variable that can only be True or False is called a:

boolean

The last line of code that is indented beneath the if statement within the for loop should be:

break

When calculating the number of pallets needed for the order, which function must be used?

ceil()

What would be printed by the following code? this_list = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(this_list[2:5])

cherry, orange, kiwi

To use a parallel lists approach to solve the homework problem, it is best to create a separate list for each ___________ in the table in the assignment.

column

When doing math in Python, it is helpful to use parentheses to

eliminate ambiguity

Which function allows us to determine the index of each element in a list?

enumerate

In the order of operations, what is calculated first if there are no parentheses?

exponents

A _____________ is a Boolean variable used in the condition to control whether or not to continue looping.

flag

To allow the cash flow at each time period to be entered in dollars and cents, what is the best Python data type to use for the variable?

float

Which type of loop is a better choice for the homework solution, since we know the number of times the loop will run?

for

Which type of loop is best to use when you know in advance how many times the loop will execute?

for

Given the code: ice_cream = ["Vanilla", "Chocolate", "Strawberry", "Butter Pecan"] ___ x ___ ice_cream: print(x) What should be in place of the blanks that would allow us to loop through the items in the ice_cream list?

for & in

Based on the business rules at the call center, which of the following formulas would be used to calculate gross pay when an employee works more than 40 hours? Assume the program uses the variables gross_pay, hourly_wage, and hours_worked

gross_pay = (hours_worked - 40) * 1.5 * hourly_wage + (40 * hourly_wage)

Which answer code is equivalent to the following? if x > 1: if y > 1: z = 10

if x > 1 and y > 1: z = 10

In order to use certain math functions such as sqrt(), one must:

import the functions from the math library

You access list items by referring to the _____________________.

index number

Which of the following items must occur before entering the loop to perform the net present value calculations in the homework program?

initialize net present value variable to 0

When the user enters the number of hours worked as a whole number, which function below should be applied to that input before calculating the gross pay?

int()

Given the following code, what is the primary function of the variable i? i=0 while i < 10: print("Go Redhawks!") i += 1

loop counter

what operator divides one number by another number to find the remainder

modulo (%)

What is displayed when the following code is run? a_dog = "fido" two_dogs = a_dog + 1 print (two_dogs)

nothing, the code contains an error

what is the productivity formula

output / input

what is the multi factor productivity formula

output / labor cost + material cost + overhead cost

What is a data structure where the indexes for each list correspond to the same entity?

parallel lists

What variables are required to calculate weekly gross pay for an hourly worker who works 40 hours or less?

pay rate in dollars per hour and number of hours worked

Assuming that we used labor_productivity as the variable for the result of the labor productivity calculation, which single line of code would output The labor productivity for the period was $132.83 per labor hour. to the screen with the labor productivity rounded to 2 decimal places?

print("The labor productivity for the period was $" + str(round(labor_productivity,2)) + "per labor hour.")

Given the following Python conditional expression: pet == "dog" and pet_color == "golden" or pet_color == "brown" How can we change this expression to ensure that the condition will only be true for a pet that is a golden or brown dog?

put parentheses around the pet_color == "golden" or pet_color == "brown" conditions

What function is used to express the gross pay in dollars and cents format? Assume the variable is called gross_pay.

round(gross_pay,2)

what does the floor function do

rounds to next lowest integer

what does the ceil function do

rounds up to the next highest integer

When defining a list, you enclose everything to the right of the equal sign in __________________.

square brackets

When using the range() function in Python, which argument must always be specified?

stop

what does the sqrt function do

takes square root of number

Given the code: for n in range (0, 30): print("I love Python!") What is the line print("I love Python!")?

the body of the loop

What is wrong with this conditional block? if y < 0: print("y is less than zero!") elif y > 0: print("y is greater than zero!") else y = 0: print("y is equal to zero!")

the else statement shouldn't have a test condition

In Python, how do you end the body of any loop?

the line of code after the body of the loop is not indented

Which of the variables in your NPV calculator is a running total?

the variable for the net present value

In the 401(k) matching program presented in the Course Pack, we included the following conditional statement: if contrib_pct < 0 or contrib_pct > 10 or annual_salary < 0: What was the purpose of this conditional?

to ensure that the user input values were in valid ranges

what does the trunc function do

truncates to lower number

The following code is intended to add one to the user's current age and then display it. What is the error in the code? current_age = input("Please enter your current age:") current_age = current_age + 1 print("Your age next year will be " + str(current_age))

you must convert current_age to a number before adding 1 to it


Set pelajaran terkait

Practice Test 2 for Principles of Management CLEP

View Set

HESI Health and Physical Assessment

View Set

NYS Driver's Ed Chapter 5 - Intersections and Turns

View Set

MKTG 480: Chapter 8 - Product strategy and new product development

View Set

NURS 3107 - Exam 4 - EAQs: Upper Respiratory Problems

View Set

Patho: Check your understanding 16,18,19,20

View Set