Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import random def piglet ( ) : Plays a game of Piglet. print ( Welcome to Piglet! ) total _ score
import random
def piglet:
Plays a game of Piglet."""
printWelcome to Piglet!"
totalscore
while True:
roll random.randint # Roll the die
printfYou rolled a roll
if roll : # Game ends if a is rolled
totalscore
break
totalscore roll # Add the roll to the total score
# Continue prompting for input until a valid response is given
while True:
rollagain inputRoll again? yn: lower
if rollagain in yn:
break
printInvalid input. Please enter y or n
if rollagain y:
break
printfYou got totalscore points."
if namemain:
piglet
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started