Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! We have to convert the pseudocode into a python program. I would really appr

ID: 3913533 • Letter: H

Question

Hi!

We have to convert the pseudocode into a python program. I would really appreciate your help. Thank you!!

Declaration num dice1 num dice2 num coputerCount nm ser.SrD um LIMI? - 2 ouekeeping detailioop) endrhile housekeeping) output "Tha tirst to 100 vins tle game o Pig coputerCoun 0 er-arn it uerIurn - 1 then else output "Computer', turn to roll the dice endii iicel random LIMIT dice2 radom LIMIT it uerIurn. 1 ther if dice 1-1 OR dice, = 1 then output "computer,? turn Count 0 endit output in:!" utpur Enter 1 to play again or inpuuexurn endit endif ” , " output er" turn

Explanation / Answer

Python3 Code:

import random

def housekeeping():

                print("The first to 100 wins the game of Pig")

                return (0, 0, 1)

def detailLoop(userCount, computerCount, userTurn, LIMIT, WIN_NUM):

                if userTurn == 1:

                                print("User's turn to roll the dice")

                else:

                                print("Computer's turn to roll the dice")

                dice1 = random.randint(1, LIMIT)

                dice2 = random.randint(1, LIMIT)

                if userTurn == 1:

                                if dice1 == 1 or dice2 == 1:

                                                print("Computer's turn")

                                                userTurn = 0

                                                if dice1 == 1 and dice2 == 1:

                                                                userCount = 0

                                else:

                                                userCount = userCount + dice1 + dice2

                                                if userCount >= WIN_NUM:

                                                                print("User wins!")

                                                else:

                                                                userTurn = int(input("Enter a 1 to play again or 0 to pass"))

                else:

                                if dice1 == 1 or dice2 == 1:

                                                print("User's turn")

                                                userTurn = 1

                                                if dice1 == 1 and dice2 == 1:

                                                                computerCount = 0

                                else:

                                                computerCount = computerCount + dice1 + dice2

                                                if computerCount >= WIN_NUM:

                                                                print("Computer wins!")

                                                else:

                                                                if random.randint(1, LIMIT) == 1:

                                                                                userTurn = 0

                                                                else:

                                                                                userTurn = 1

                return (computerCount, userCount, userTurn)

def finishUp():

                print("End of program")

LIMIT = 2

WIN_NUM = 100

(userCount, computerCount, userTurn) = housekeeping()

while computerCount < WIN_NUM and userCount < WIN_NUM:

                (computerCount, userCount,userTurn) = detailLoop(userCount,computerCount, userTurn, LIMIT, WIN_NUM)

finishUp()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote