part 1 In the game of Lucky Sevens, the player rolls a pair of dice. If the dots
ID: 3666550 • Letter: P
Question
part 1
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4, otherwise, the player loses $1.
Write a python program to start a game by asking the player how much he/she wants to put into the pot (input as floating point). Then roll the pair of dice.
If total is 7, display “You won!” and add $4 to the pot, otherwise display “You lost!” and subtract $1 from the pot.
At end display how much the player has left in the pot.
PART-2
Make necessary changes in part-1 to allow the game to continue as long as the player wishes or has money left in the pot.
import random
in order to use random.randint(1,6) for generating a random integer between 1 and 6
Explanation / Answer
import random
mypot = input("Please enter the amount of money you want in the pot: ")
while mypot > 0:
dice_roll = random.randint(1, 7), random.randint(1, 7)
print dice_roll[0], dice_roll[1]
myrole = sum(dice_roll)
if myrole == 7:
mypot += 4
print "Your roll was a 7 you earned. Press enter to roll again:", mypot
else:
mypot -= 1
print "Sorry you did not roll a 7. Press enter to roll again:", mypot
raw_input()
print "Sorry, there's no more money in your pot."
Method-2
import random
mypot = int(input("Please enter the amount of money you want in the pot: "))
diceroll1 = random.randint(1, 7)
diceroll2 = random.randint(1, 7)
myrole = (diceroll1 + diceroll2)
while mypot > 0:
if myrole == 7:
print("Your roll was a 7 you eaerned press enter to roll again: ", mypot + 4)
break
else:
print("Sorry you did not roll a 7 press enter to roll again: ", mypot - 1)
break
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.