Uploaded by anureetkaur0728

Project+1+-+COMP+905

advertisement
PYTHON Project 1– Loops, Logic and Counting
For this assignment, you will have a choice of creating a Rock-Paper-Scissors game OR writing a program that
experimentally validates the Monty Hall Problem. Both assignments will require the use of strings,
comparators, conditionals, loops, and counters. Please only submit one or the other.
Rock, Paper, Scissors – firstRPS_studentid.py
Instructions:
Write a program that simulates a game of Rock-Paper-Scissors between a human user and the
computer.
Criteria:
 Provide an introduction to the user by displaying text to the screen when the program is started. Be
sure to include what input is required from the user.
 Ask the user how many rounds they wish to play. Set up a for loop to ensure the game is played the
correct number of times.
 Use input() to get the human player's choice. Be sure to include prompt text. The input should be
“rock”, “paper” or “scissors” and should be case insensitive. You can achieve this by using upper() or
lower().
 If the user enters an incorrect choice (ie: laser sword), continue to prompt them until they do provide a
valid entry (hint: use a while loop).
 Use randint() to generate the computer’s choice of weapon. Remember to import random at the
top of your program to use this function.
 Use if statements to evaluate who is the winner and who is the loser. There will be 9 possible
combinations. You can use nested ifs or compound conditional statements. Make sure you check the
user’s input first to give yourself more control over your test cases. There can also be a tie!
 Use appropriate text messages when the user looses.
 Ensure that you show what the user chose, what the computer chose and who was the winner. Ties
can also occur.
 Lastly, at the end of the n rounds, indicate the stats based on the computer’s picks. Include number of
times and percentage each weapon was chosen and percentage of wins when it was chosen. For
example, see below (though does not have to match exactly, should contain the same information):
10 rounds of Rock-Paper-Scissors was played.
• Rock was chosen 3 times (30%) and won 67% of the time.
• Paper was chosen 4 times (40%) and won 75% of the time.
• Scissors was chosen 3 times (30%) and won 33% of the time.
• Overall, after 10 rounds, human: 4 – computer 6
Computers win this time!
•
Always include an updated header and provide meaningful comments to explain your code.
Worth 20% of marks
Monty Hall Problem –firstMH_studentid.py
Instructions:
Write a program that simulates the Monty Hall Problem of choosing a prize that lies behind one of 3
doors. The problem should randomly place a prize behind door 1, 2 or 3 and present the user with a
choice of the 3 doors. The program should then reveal one of the unchosen doors that does not
contain the prize and give the user a chance to switch their choice. Finally, the program should reveal
which door the prize was behind and indicate if the user was correct, and if they had switched from
their original choice. In addition to interactively asking the user for their selection, you should have a
second mode that will simulate the choice x times. Ask the user how many times to run it. Report the
stats to the screen.
Criteria:
• Provide an introduction to the user by displaying text to the screen when the program is started. Be
sure to include what input is required from the user.
• Ask the user how many rounds they wish to play. Set up a for loop to ensure the game is played the
correct number of times.
• Use input() to get the player's choice of doors. Be sure to include prompt text. The input should be
“1”, “2” or “3”.
• If the user enters an incorrect choice (ie: 4), continue to prompt them until they do provide a valid
entry (hint: use a while loop).
• Use randint() to generate the number of the door that will contain the prize. Remember to include
random to use this function.
• Use if statements to determine which of the other door unchosen doors contains the prize and reveal
the one that does not. Ask the user if they want to switch their original answer (yes or no).
• Allow the yes/no answer to be case insensitive. You can achieve this by using upper() or lower().
• Evaluate if the user chose the door with the prize (considered a win) and record if the user “won” and
if they had chosen to switch or keep their original guess. Include appropriate text messages when a
user looses.
• At the end of the n rounds, indicate the stats based on the user’s picks. Include number of times the
user switched and if they “won” when they did. For example, see below (though does not have to
match exactly, should contain the same information):
10 rounds of Monty Hall problem were presented.
• User switched their response 50% of the time.
• When the user switched their response, they won 80% of the time.
• When the user did not switch their response, they won 40% of the
time.
• Overall, after 10 rounds, user won 6 of the 10 times, and won
more when they switched their response (80% versus 40%).
Worth 20% of marks
Download