Question: using python, fix any issues with this code: from random import randint print ( You have two choices ) print ( Option 1
using python, fix any issues with this code: from random import randint
printYou have two choices"
printOption : Cooperate with the Authorities"
printOption : Stay Silent"
partnerAchoice intinputEnter or :
partnerBchoice randint
printfYou chose partnerAchoice
printfThe computer chose partnerBchoice
if partnerAchoice and partnerBchoice :
printYou both do years in prison"
elif partnerAchoice and partnerBchoice :
printYoure released!!"
printThe computer does years in prison"
elif partnerAchoice and partnerBchoice :
printYou do years in prison"
printThe computer is released!"
elif partnerAchoice and partnerBchoice :
printYou both do years in prison"
partnerAcount
partnerBcount
for i in range:
partnerAChoice randint
partnerBChoice randint
if partnerAChoice and partnerBChoice :
partnerAcount
partnerBcount
elif partnerAChoice and partnerBChoice :
partnerAcount
partnerBcount
elif partnerAChoice and partnerBChoice :
partnerAcount
partnerBcount
else:
partnerAcount
partnerBcount
averageA partnerAcount
averageB partnerBcount
printPartner A spent', partnerAcount, 'years in jail'
printPartner B spent', partnerBcount, 'years in jail'
printOn average, Partner A spent', averageA, 'years in jail'
printOn average, Partner B spent', averageB, 'years in jail'
numtrials
while numtrials or numtrials :
try:
numtrials intinputHow many trials should be simulated?
if numtrials or numtrials :
printPlease enter a number between and
except ValueError:
printInvalid input. Please enter an integer.
for i in rangenumtrials:
partnerAChoice randint
partnerBChoice randint
averageA partnerAcount numtrials
averageB partnerBcount numtrials
printAverage for Partner A: averageA
printAverage for Partner B: averageB
partnerAstrategy
while partnerAstrategy or partnerAstrategy :
partnerAstrategy intinputSelect a strategy for Partner A Random, Only Silent, Only Cooperates:
if partnerAstrategy or partnerAstrategy :
printMust enter a number between and
Please try again'
partnerBstrategy
while partnerBstrategy or partnerBstrategy :
partnerBstrategy intinputSelect a strategy for Partner B Random, Only Silent, Only Cooperates:
if partnerBstrategy or partnerBstrategy :
printMust enter a number between and Please try again'
numtrials
while numtrials or numtrials :
numtrials intinputHow many trials should be simulated?
if numtrials or numtrials :
printPlease enter a number between and
for i in rangenumtrials:
if partnerAstrategy :
partnerAChoice randint
elif partnerAstrategy :
partnerAChoice
else:
partnerAChoice
if partnerBstrategy :
partnerBChoice randint
elif partnerBstrategy :
partnerBChoice
else:
partnerBChoice
averageA partnerAcount numtrials
averageB partnerBcount numtrials
printPartner A did an average of averageA, 'years in prison'
printPartner B did an average of averageB, 'years in prison'
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
