4.12.1 Python Control Structures Quiz

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What will the following program print when run? number_one = 5 number_two = 10 if number_one == 5: print(1) if number_one > 5: print(2) if number_two < 5: print(3) if number_one < number_two: print(4) if number_one != number_two: print(5)

1 4 5

The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.

Add a break; statement after line 6 so that the program doesn't loop infinitely

What is the output of the following program? result = 0 max = 5 for i in range(max): result += i print(result)

10

What is the last thing printed by the following program? start = 30 stop = 10 for i in range(start, stop - 1, -5): if i % 2 == 0: print(i * 2) else: print(i)

20

What will be the output of this program? number = 5 greater_than_zero = number > 0 if greater_than_zero: print(number)

5

What will the following program print when run? for j in range(2): for i in range(6, 4, -1): print (i)

6 5 6 5

What will the following program print when run? above_16 = True has_permit = True passed_test = False if above_16 and has_permit and passed_test: print("Issue Driver's License") else: if above_16 or has_permit or passed_test: print("Almost eligible for Driver's License") else: print("No requirements met.")

Almost eligible for Driver's License

What is the value of the boolean variable can_vote at the end of this program? age = 17 is_citizen = True can_vote = age >= 18 and is_citizen

False

We want to print the phrase "CodeHS is the best" exactly 25 times. What kind of control structure should we use?

For Loop

What is printed by the following program? num_apples = 10 num_oranges = 5 if num_apples < 20 or num_oranges == num_apples: print("Hello, we are open!") else: print("Sorry, we are closed!") print("Sincerely, the grocery store")

Hello, we are open!Sincerely, the grocery store

The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤.As well, AND, OR and NOT are used instead of and, or and not. In the following code block, assume that the variables rainy and tooCold are boolean. IF ((NOT rainy) AND (NOT tooCold)) { DISPLAY("It's a good beach day") } Which of the following are equivalent to the above code block?

IF (NOT (rainy OR tooCold)) { DISPLAY("It's a good beach day") }

What is printed by the following program? is_raining = False is_cloudy = False is_sunny = not is_raining and not is_cloudy is_summer = False is_warm = is_sunny or is_summer print("Is it warm: " + str(is_warm))

Is it warm: True

What will be the output of this program? number = 5 greater_than_zero = number > 0 if greater_than_zero: if number > 5: print(number)

Nothing will print

How many times will the following program print "hello"?

This code will loop infinitely

What will be the output when the following code runs? logged_in = False print("User logged in?: " + str(not logged_in))

User logged in?: True

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?

While Loop


Kaugnay na mga set ng pag-aaral

Chapter Exam - Life Policies (LAH_Texas)

View Set

Chapter 4 Building Styles and Construction

View Set

Digestive System and Metabolism Exam Study Guide (Pt. 4)

View Set

Stratification/INEQUALITY: crime, education, incarceration, income, labor market, policing, poverty, wealth

View Set