# Chapter 04 Worksheet

Reminder: Please use full sentences, capital letters, and proper grammar where appropriate.

Don't create a loop that only loops once. That doesn't make sense. Python runs the code once by default anyway. Avoid loops like this:

for i in range(1):
# Do something.

1. Write a Python program that will use a for loop to print your name 10 times, and then the word Done'' at the end.
2. Write a Python program that will use a for loop to print Red'' and then Gold'' 20 times. (Red Gold Red Gold Red Gold... all on separate lines. Don't use \n.)
3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive.
4. Write a Python program that will use a while loop to count from 10 down to, and including, 0. Then print the words Blast off!'' Remember, use a WHILE loop, don't use a FOR loop.
5. There are three things wrong with this program. List each. (3 pts)
print("This program takes three numbers and returns the sum.")
total = 0

for i in range(3):
x = input("Enter a number: ")
total = total + i
print("The total is:", x)

6. Write a program that prints a random integer from 1 to 10 (inclusive).
7. Write a program that prints a random floating point number somewhere between 1 and 10 (inclusive). Do not make the mistake of generating a random number from 0 to 10 instead of 1 to 10.
8. Write a Python program that will: (3 pts)
• Ask the user for seven numbers
• Print the total sum of the numbers
• Print the count of the positive entries, the number entries equal to zero, and the number of negative entries. Use an if, elif, else chain, not just three if statements.
9. Coin flip tosser: (4 pts)
• Create a program that will print a random 0 or 1.
• Instead of 0 or 1, print heads or tails. Do this using if statements. Don't select from a list, as shown in the chapter.
• Add a loop so that the program does this 50 times.
• Create a running total for the number of heads flipped, and the number of tails.
10. Write a program that plays rock, paper, scissors: (4 pts)
• Create a program that randomly prints 0, 1, or 2.
• Expand the program so it randomly prints rock, paper, or scissors using if statements. Don't select from a list, as shown in the chapter.
• Add to the program so it first asks the user their choice.
• (It will be easier if you have them enter 1, 2, or 3.)
• Add conditional statement to figure out who wins.
﻿