COSC1306 Spring 2017 Assignment 4: Loops [1] Objectives: The

COSC1306
Spring 2017
Assignment 4: Loops
[1] Objectives: The primary purpose of this assignment is to make sure everyone is familiar with the
while and for loops. In addition to that, we are practicing other statements introduced in class: print(),
input(), assignment, and if statements. Guidance will be given regarding the random number generation
and specific seed to use so we get the same answers. You are required to use at least one while loop
and one for loop.
[2] Description: You will be doing some experiments with the random number generator function.
Please read the documentation on the Python's "random" module. You are going to run multiple
iterations of a menu entry system with 5 options. The Menu System should look like the following and
you run in a while loop until a 5 or invalid option is entered:
Dice Menu:
1: Return the number of single dice rolls to get a six
2: Roll two dice 1000 times and return the number of times the dice total was 7
3: Roll one dice 10 times and print the value for each roll
4: Reset the seed
5: Quit
Enter your selection:
Your program should do the following things:
1. You should import “random” so that you will be able to use the random number generator. Set
the seed to 99.
2. Print the menu.
3. Prompt the user to input the choice.
4. Process the choice (use if/elif/else here).
5. For option 1: Find out the number of times you call randint() until you get a 6. Print the number
of times.
6. For option 2: Find out how many times in 1000 attempts can we get a total of 7 if we roll the
dice twice. Finally, print the number of times your result adds to 7.
7. For option 3: Print the next 10 random numbers representing one dice roll.
8. For option 4: Ask the user to enter a new random seed using the seed function.
9. For option 5: Print a message such as “Exiting the program” and stop your Menu from coming
up.
The program should continue to run until the user decided to quit.
[3] Input: Test your program thoroughly.
[4] Output: Here are some sample screens.
Dice Menu:
1: Return the number of single dice rolls to get a six
2: Roll two dice 1000 times and return the number of times the dice total was 7
3: Roll one dice 10 times and print the value for each roll
4: Reset the seed
5: Quit
Enter your selection: 1
It took 11 dice rolls to get a 6.
Dice Menu:
1: Return the number of single dice rolls to get a six
2: Roll two dice 1000 times and return the number of times the dice total was 7
3: Roll one dice 10 times and print the value for each roll
4: Reset the seed
5: Quit
Enter your selection: 3
4 6 6 5 2 3 2 5 6 5
Dice Menu:
1: Return the number of single dice rolls to get a six
2: Roll two dice 1000 times and return the number of times the dice total was 7
3: Roll one dice 10 times and print the value for each roll
4: Reset the seed
5: Quit
Enter your selection: 4
Enter a seed: 171
[5] Deadline: Monday, February 27, 2017
Remarks: If you are not clear about the requirements, feel free to ask the instructor or the TAs. Please
do not send a copy of your program to the professor or the TAs and asking him if the program is it what
he wanted (i. e., you are getting a perfect points).