Python: Boxcar simulates rolling 2 dices; you win when you roll 2 sixes. Downloa
ID: 3592404 • Letter: P
Question
Python:
Boxcar simulates rolling 2 dices; you win when you roll 2 sixes. Download this imperative file and run it on Python. You will then delete the imperative code, uncomment the functional template, then add your own code to complete the task. When completed, your functional code should contain
1.No global variables, preferably no variables all
2. If you have local variables, make sure they are immutable
3. No looping
The output should be identical
https://pastebin.com/Z6FwXWzN
from random import randint dice 1 = list() # history of dice 1 as entries in a list dice2 = list() # history of dice2 as entries in a list win False # weither last throw was a boxcar def roll (d) d.append(randint (1,6)) # simulate rolling a dice, by pushing a 1-to-6 into 11st return while not win: roll (dicel) roll (dice2) if dice1 [-1] 6 and dice2-16: win = True print (dice!) # print history print (dice2) # print history print('Boxcars in', len (dice1), 'throws') ## (delete above and uncomment & fix up below) ## from random import randint ## def printhistory (State): ## # # print (state[ 'dicel']) print (state [ ' dice2 ' ] ) print ( ' Boxcars in· len (state [ ' dice 1 ' ] ) , ' throws ' ) ## def nextthrow (state) : ## # Your code goes here # # nextthrow ( { ' dice! ' : list ( ) , ' dice2 ' : list ( ) } )Explanation / Answer
from random import randint
def rollDice():
print(randint(1,6))
def askRoll(ans):
yes = "yes"
no = "no"
if yes in ans:
rollDice()
return(True)
elif no in ans:
print(" Okay, until next time!")
return(False);
else:
print(" Your response was incorrect")
return (True)
print("Dice rolling simulator! ")
rollDice()
anotherTime = "True"
while anotherTime:
print("Would you like to roll again? ")
ans = input("> ")
anotherTime = askRoll(ans)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.