Question: Using python write the code using these instructions: 2 Ways to do this: 1 . Put a for count in range ( 5 ) :

Using python write the code using these instructions: 2 Ways to do this:
1. Put a for count in range(5): loop around your entire code
2. Make your code a function that runs one simulation and returns the years in jail of
partner A and B in an array/list (cleaner imo)
Make partnerAcount and partnerBcount variable at the top
(or if you do the function before you call the function)
In your if/elif/else statements add the corresponding years to partnerAcount
and partnerBcount.
(the if statements where it prints the You both do 4 years/Youre released...)
To find the averages, divide the counts by 5.
Later, this 5 will become a variable, so make a variable, count =5, and put it in
range(count) and do partnerAcount/count
If you hardcoded 5 trials, you should change that to a count variable
At the very top, call input() and ask how many trials they want.
(Or above the function call if you used a function)
count = int(input(How many trials should be simulated))
Make a while statement that checks that the user entered a number
between 10 and 500.
Inside the while statement, if they didnt enter a valid number:
Print Please enter a number between 10 and 500
then ask again for a number using input and store that into the count variable.
Copy and paste the menu text from the canvas page and print that out
Make a strategy variable (partnerAStrat) for player A and then use input to
get user input for that strategy.
Check if its not between 1 and 3 using a while loop. Something like
while(partnerAStrat <1 or partnerAStrat >3):
Inside the while loop:
Print Must enter a number between 1 and 3
Please try again
Ask for another input
Repeat the step above for player B
Once you have partnerAStrat and partnerBStrat...
Where you declared partnerAChoice and partnerBChoice, make an if/elif/else ladder
that sets the choices to 1,2, or randint(1,2).
If you did a function approach, you might have to pass in extra arguments for the
strategy in your function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!