Pyhton - In the game of Lucky Sevens, the player rolls a pair of dice. If the do
ID: 3736081 • Letter: P
Question
Pyhton - 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. Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1, 6), (2,5), etc. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people’s eyes glaze over at the first mention of mathematics, your challenge is to write a program that demonstrates the futility of playing the game. Your program should take as input the amount of money that the player wants to put into the pot, and play the game until the pot is empty. At that point, the program should print the number of rolls it took to break the player, as well as maximum amount of money in the pot.
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.