Quiz 4

¡Supera tus tareas y exámenes ahora con Quizwiz!

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


Conjuntos de estudio relacionados

Chapter 11: Cash Flow Forecasting

View Set

Chapter 11 - Organizational Design: Structure, Culture, and Control

View Set

1) Distinguish between altruism and pro-social behaviour

View Set

Exam 3: SIADH, Diabetes Insipidus

View Set

Chapter 8. Structuring Organizations for Todays Challenges

View Set

sociology combination set for final

View Set

Exam 2: Theology 1001, Exam 1 - Theology 1001 - 138

View Set