# 5.34. Functions with Loops Multiple Choice Questions¶

- 1
- Try again! This function uses modulus to find the amount of odd numbers in the list that is passed in.
- 2
- Try again! This function uses modulus to find the amount of odd numbers in the list that is passed in.
- 3
- Correct!
- 4
- Try again! This function uses modulus to find the amount of odd numbers in the list that is passed in.
- 5

p9-1: Given the code below, what would the function print?

```
def countodd(lst):
num_of_odd = 0
for item in lst:
if item % 2 == 1:
num_of_odd += 1
return num_of_odd
print(countodd([1,2,3,4,5]))
```

- 50
- Try again! This function will divide the number that is passed in by two until it reaches one.
- 25
- Try again! This function will divide the number that is passed in by two until it reaches one.
- 5
- Try again! This function will divide the number that is passed in by two until it reaches one.
- 6
- Correct!
- 2
- Try again! This function will divide the number that is passed in by two until it reaches one.

p9-2: After how many iterations will this code execute the `break`

?

```
def divide_by_two_until_one(num):
count = 0
while (True):
num = num/2
count = count + 1
if (num <= 1):
break
return count
print(divide_by_two_until_one(50))
```

- x = 5, y = 6, z = 11
- Correct!
- x = 1, y = 5, z = 6
- Correct!
- x = 1, y = 3, z = 10
- Try again! The value of z should be 4 in order to return "True".
- x = -2, y = 1, z = -1
- Correct!
- x = 50, y = 41, z = 94
- Try again! The value of z should be 91 in order to return "True".

p9-3: Which of the following values for `x`

, `y`

, and `z`

would result in the function returning “True”?

```
def addition(x,y,z):
if (x + y) == z:
return "True"
else:
return "False"
```

- 3
- Try again! The in range function has an inclusive end value.
- 4
- Correct!
- 0
- Try again! The in range function has an inclusive end value.
- 5
- Try again! The in range function has an inclusive end value.

p9-4: How many times would `"Hello world!"`

print?

```
for i in range(4):
print("Hello world!")
```

- It prints 19 times and it skip counts by the current value in lst2.
- Try again! For loops include the last element.
- It prints 20 times and it skip counts by the current value in lst1.
- Try again! This code counts by the second list.
- It prints 19 times and it skip counts by the current value in lst1.
- Try again! For loops include the last element and count by the second list.
- It prints 20 times and it skip counts by the current value in lst2.
- Correct!

p9-5: How many times does the following code print and in what pattern?

```
lst1 = [1, 3, 5, 7]
lst2 = [2, 4, 6, 8, 10]
for x in lst1:
for y in lst2:
print(x * y)
```

You have attempted of activities on this page