게시 한 코드는 끝날 때까지 3 개의 가짜 난수를 선택하지 않습니다. 승리/손실 조건을 추가해야합니다. 현재 x, y 및 z는 숫자입니다. 당신이 도박 게임을하고 싶다면 당신은 같은 몇 가지 승리 조건을 추가 할 수 있습니다
if x + y + z > 10
단지 예를 들어 있지만, 당신의 프로그램은 선수가 우승하면 말할 수 있어야합니다. 플레이어에게 총 금액을 변경하고 새 베팅을 요청해야합니다. 또한 플레이어가 가지고있는 것보다 더 많은 내기를 할 수 없도록 논리를 추가 할 수도 있습니다.
import random
coins = 1000
wager = 0
while True: #main loop
print('you have {} coins'.format(coins))
if coins == 0: #stops the game if the player is out of money
print('You are out of money! Scram, deadbeat!')
break
while wager > coins or wager == 0: #loops until player enters a non-zero wager that is less then the total amount of coins
wager = int(input('Please enter your bet (enter -1 to exit): '))
if wager < 0: # exits the game if the player enters a negative
break
print('All bets are in!')
x = random.randint(0,10)
y = random.randint(0,10)
z = random.randint(0,10)
print(x,y,z) #displays all the random ints
if x + y +z > 10: #victory condition, adds coins for win
print('You win! You won {} coins.'.format(wager))
coins += wager
else: #loss and deduct coins
print('You lost! You lose {} coins'.format(wager))
coins -= wager
wager = 0 # sets wager back to 0 so our while loop for the wager validation will work
들여 쓰기는 Python에서 중요합니다. 코드를 반영하기 위해'while' 다음에 줄을 들여 쓰기를 할 수 있습니까? –