Chapter 04 Worksheet

Return to worksheet index.

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)
  9. Coin flip tosser: (4 pts)
  10. Write a program that plays rock, paper, scissors: (4 pts)