Quiz 4
Consider the following code segment: count = 5 while count > 1: print(count, end = " ") count -= 1 What is the output produced by this code?
5 4 3 2
What are the 4 things that a while statement will always consist of?
A condition (that is, an expression that evaluates to True or False) A colon While clause The while keyword
Consider the following code segment: theSum = 0.0 while True: number = input("Enter a number: ") if number == "": break theSum += float(number) How many times will the loop run?
At least once
By default, the while loop is an:
Entry controlled loop
What value does a Python function return if no return statement is specified in the function?
None
Consider the following code segment: count = 1 while count <=10: print(count, end = " ") Which of the following describes the error in this code?
The loop is infinite
What two statements can be used to handle exceptions in our Python code?
Try Except
Given this Python code: fruits = ['apple' , 'banana', 'cherry'] def fruit(food): for x in food: print(x) What will be the output when this next line of code is executed? fruit(fruits)
apple banana cherry; printed vertically on separate lines
Write a function called, add, which will add two numbers together. Use two parameters in your function named: a and b To indent in the essay box, use two spaces for each indention
def add(a,b): return a + b
Write the first line of code to create a new function called, hello, with two arguments, a and b. Only include the minimum number of spaces for the syntax to be correct.
def hello(a,b):
Write Python code to define a function called, multiply, that will multiply two numbers. Use two parameters in your function named: a and b To indent in the essay box, use two spaces for each indention
def multiply(a,b): return a * b
Write Python code to define a function called, subtract, that will subtract two numbers. Use two parameters in your function named: a and b To indent in the essay box, use two spaces for each indention
def subtract(a, b): return a - b