Question: Convert the pseudocode into Python start Declarations num dice1 num dice2 num userCount num computerCount num userTurn num LIMIT = 2 num WIN_NUM =100 housekeeping()

Convert the pseudocode into Python

start Declarations num dice1 num dice2 num userCount num computerCount num userTurn num LIMIT = 2 num WIN_NUM =100 housekeeping() while computerCount < WIN_NUM AND userCount < WIN_NUM detailLoop() endwhile stop housekeeping() output The first to 100 wins the game of Pig userCount = 0 computerCount = 0 userTurn = 1 return detailLoop() if userTurn = 1 then output Users turn to roll the dice else output Computers turn to roll the dice endif dice1 = random(LIMIT) dice2 = random(LIMIT) if userTurn = 1 then if dice1 = 1 OR dice2 = 1 then output Computer's turn userTurn = 0 if dice1 = 1 AND dice2 = 1 then userCount = 0 endif else userCount = userCount + dice1 + dice2 if userCount >= WIN_NUM output User wins! else output Enter a 1 to play again or 0 to pass input userTurn endif endif else if dice1 = 1 OR dice2 = 1 output User's turn userTurn = 1 if dice1 = 1 AND dice2 = 1 THEN computerCount = 0 endif else computerCount = computerCount + dice1 + dice2 if computerCount >= WIN_NUM output Computer wins! else if random(LIMIT) = 1 then userTurn = 0 else userTurn = 1 endif endif endif endif return finishUp() output End of program return

My solution which gives me errors:

def housekeeping(): print( The first to 100 wins the game of Pig) userCount = 0 computerCount = 0 userTurn = 1 return def detailLoop(): if userTurn = 1 then output Users turn to roll the dice else output Computers turn to roll the dice endif dice1 = random(LIMIT) dice2 = random(LIMIT) if userTurn = 1 then if dice1 = 1 OR dice2 = 1 then output Computer's turn userTurn = 0 if dice1 = 1 AND dice2 = 1 then userCount = 0 endif else userCount = userCount + dice1 + dice2 if userCount >= WIN_NUM output User wins! else output Enter a 1 to play again or 0 to pass input userTurn endif endif else if dice1 = 1 OR dice2 = 1 output User's turn userTurn = 1 if dice1 = 1 AND dice2 = 1 THEN computerCount = 0 endif else computerCount = computerCount + dice1 + dice2 if computerCount >= WIN_NUM output Computer wins! else if random(LIMIT) = 1 then userTurn = 0 else userTurn = 1 endif endif endif endif return def finishUp(): print (End of program) return

#Main start #Declarations dice1=0 dice2=0 userCount=0 computerCount=0 userTurn=0 LIMIT = 2 WIN_NUM =100

housekeeping() while computerCount < WIN_NUM and userCount < WIN_NUM: detailLoop()

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 Databases Questions!