Andre Harris II
Andre Harris II

Reputation: 1

Lucky Sevens Game (beginner)

I am having trouble getting the program to repeat the loop until mypot != 0. The object of the program is to ask user for amount of money to put in the pot, and ask user to roll dice until mypot !=0

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 True:
    mypot > 0
if myrole == 7:
    print("Your roll was a 7 you eaerned press enter to roll again:  ", mypot + 4)
    break
elif  myrole != 0
    print("Sorry you did not roll a 7 press enter to roll again: ", mypot - 1)
    break
elif mypot != 0:
    print("Sorry you do not have no more money in your pot")
    break

Update: I am having trouble getting the program to repeat the loop until mypot == 0

import random

mypot = int(input("Please enter the amount of money you want in the pot: "))
while mypot > 0:    # looping untill mypot <= 0
  dice_roll = random.randint(1, 7), random.randint(1, 7)  # rolling the dices
print(dice_roll[0], dice_roll[1])
myrole = sum(dice_roll)
if myrole == 7:
    mypot += 4    # without this you're not modifing the myrole value
    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)
input()   # waiting for the user to press Enter

print("Sorry, there's no more money in your pot.")

Upvotes: 0

Views: 5507

Answers (2)

Rik Poggi
Rik Poggi

Reputation: 29302

Your while loop is quite strange: elif mypot != 0 will never be cheked, beacuse either one of the previous condition will be True, so your while loop isn't also a loop at all.

To fix that you need to change:

elif mypot != 0:
    print "Sorry you do not have no more money in your pot"
    break

with:

if mypot != 0:
    print "Sorry you do not have no more money in your pot"
    break

And put this before the other ifs.

But your code seems to have other issues:

There's:

mypot > 0

Right after the while True, why it's not:

while mypot > 0:
    # ...

Also the value of myrole doesn't seem to be modified in the while loop, so what's that while non-loop doing there?

DSM is suggesting that you're trying to use that while non-loop as a switch.

I think you're trying to do something like:

import random

mypot = input("Please enter the amount of money you want in the pot: ")
# or as alternative:
#mypot = int(raw_input("Please enter the amount of money you want in the pot: "))
while mypot > 0:    # looping untill mypot <= 0
    dice_roll = random.randint(1, 7), random.randint(1, 7)  # rolling the dices
    print dice_roll[0], dice_roll[1]
    myrole = sum(dice_roll)
    if myrole == 7:
        mypot += 4    # without this you're not modifing the myrole value
        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()   # waiting for the user to press Enter

print "Sorry, there's no more money in your pot."

Upvotes: 1

Alexander Corwin
Alexander Corwin

Reputation: 1167

There's a few things wrong with this. First of all, since python uses what's called semantic whitespace, the indentation matters. So where you have

while True:
 mypot > 0
if myrole == 7:
    print("Your roll was a 7 you eaerned press enter to roll again:  ", mypot + 4)
    break

it's reading this as: while True, evaluate (mypot > 0). Then move on to the if statement. Your elifs should be on the same level of indentation as your if statement, as well, and you need a colon after your frist elif.

Anyway, that's probably not the biggest issue. Inside your loop, you dont have anything changing. You need to move that while True: statement up to the ilne right above diceroll1. All the code after while True: will be what executes over and over, and inside your while loop now the value of myrole isn't getting reassigned.

Upvotes: 0

Related Questions