While loop activities
While loops or indefinite loops are a very important programming construct — they allow us to continue executing code until a particular condition stops being true. (See the Text book section: While Loops).
You will complete activities 1 and 2 and your choice of 3 or 4. Write all of these in a single file with each activity in its own function.
Activity 1: Countdown
Write a program that asks the user for a number, and prints a countdown from that number to zero. What should your program do if the user inputs a negative number? As a programmer, you should always consider “edge conditions” like these when you program! (Another way to put it- always assume the users of your program will be trying to find a way to break it! If you don’t include a condition that catches negative numbers, what will your program do?)
Activity 2:
Write a function named dice_sum. This function should prompt the user for a desired sum then repeatedly roll two six-sided dice until their sum is the desired sum. Here is what a run of your program should look like (user input underlined):
What sum are you looking for? 6
Rolled a 4 and a 4
Rolled a 6 and a 5
Rolled a 2 and a 6
Rolled a 5 and a 6
Rolled a 4 and a 2
Got a 6 in 5 rolls!
Activity 3: Multiplication tutor
Feel free to take some freedom with the messages displayed to users!
You are trying to help your younger sibling/cousin/neighbor learn to multiply. Your task is to write a multiplication tutor. Your game should display a welcome message including the player’s name. It should then randomly generate two numbers and ask the player to type out their product. The player should get one point for every correct answer. The game should keep going until the user types in -1. After the game is over, the player’s score should be displayed.
Here is what your game should look like — user input is underlined:
Welcome to the multiplication tutor!
What is your name? Ms. Martin
Let’s see how good you are at multiplication, Ms. Martin.
Type -1 at any time to exit and see your score
What is 5 * 8? 40
Correct!
What is 8 * 8? 64
Correct!
What is 7 * 10? 77
NO! The answer was 70
What is 7 * 9? 9
NO! The answer was 63
What is 5 * 5? 25
Correct!
What is 9 * 9? -1
Thanks for playing, Ms. Martin! You scored 3 points.





