我很難讓程序重複循環,直到mypot != 0
。該計劃的目的是詢問用戶的金額放於鍋中,並要求用戶擲骰子直到mypot !=0
Lucky Sevens遊戲(初學者)
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
更新:我有麻煩的程序重複循環直到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.")
用四個空格修復縮進。 – eumiro 2012-02-20 13:25:08