6. How are while loops and for loops different in Python?
- While loops can be used with all data types, for loops can only be used with numbers.
- For loops can be nested, but while loops can’t.
- While loops iterate while a condition is true, for loops iterate through a sequence of elements.
- While loops can be interrupted using break, for loops using continue.
7. Which option would fix this for loop to print the numbers 12, 18, 24, 30, 36?
for n in range(6,18,3): print(n*2)
for n in range(6,18,3):
8. Which for loops will print all even numbers from 0 to 18? Select all that apply.
9. Fill in the blanks so that the for loop will print the first 10 cube numbers (x**3) in a range that starts with x=1 and ends with x=10.
for __ in range(__,__): print(__)
for __ in range(__,__):
10. Write a for loop with a three parameter range() function that prints the multiples of 7 between 0 and 100. Print one multiple per line and avoid printing any numbers that aren't multiples of 7. Remember that 0 is also a multiple of 7.
for ___: print(___)