Максимальная сумма в деньгах - PullRequest
0 голосов
/ 20 апреля 2020

Мне нужно показать максимальную сумму денег в банке, но я всегда получаю «0» или, когда я пытаюсь внести их в список, это не работает. Остальная часть программы работает нормально, но я просто не знаю, как показать максимальную сумму денег, которая была в куче денег. вот мой код:

import random
def main():
    """
    param: None
    return: None
    """
    print("Welcome to Lucky Sevens! Take your chances and win big if the die equal to 7! There are many ways to win!")
    pot_money = 0
    initial_bet = float(input("Enter your bet: "))
    die1 = random.randint(1,6)
    die2 = random.randint(1,6)
    diceTotal = die1 + die2
    roll_number = 0

    #pot money would be equal to the initial bet until the player starts to gamble or it is empty
    pot_money = initial_bet + pot_money
    while pot_money > 0:


        diceTotal = die1 + die2
        roll_number += 1
        print("Die 1 was " + str(die1) + " and die 2 was " + str(die2))
        print("The total of the die was: " + str(diceTotal))
        print("You are currently on roll " + str(roll_number))
        if diceTotal == 7:
            pot_money = pot_money + 4
        else:
            pot_money = pot_money - 1
            if pot_money == 0:
                print("It took " + str(roll_number) + " rolls to break you.")
                print("The maximum amount of money in the pot was " + max(str(pot_money)))

        print("The pot currently holds: $" + str(pot_money))
        die1 = random.randint(1,6)
        die2 = random.randint(1,6)



main()

1 Ответ

1 голос
/ 20 апреля 2020

Попробуйте этот код. Это печатает максимальный банк в конце. Вам просто нужно сохранить переменную для максимального банка и постоянно обновлять ее в l oop:

import random

print("Welcome to Lucky Sevens! Take your chances and win big if the die equal to 7! There are many ways to win!")
pot_money = 0
initial_bet = float(input("Enter your bet: "))
die1 = random.randint(1,6)
die2 = random.randint(1,6)
diceTotal = die1 + die2
roll_number = 0



#pot money would be equal to the initial bet until the player starts to gamble or it is empty
pot_money = initial_bet + pot_money
max_pot = pot_money

while pot_money > 0:

    diceTotal = die1 + die2
    roll_number += 1
    print("Die 1 was " + str(die1) + " and die 2 was " + str(die2))
    print("The total of the die was: " + str(diceTotal))
    print("You are currently on roll " + str(roll_number))
    if diceTotal == 7:
        pot_money = pot_money + 4
    else:
        pot_money = pot_money - 1
        if pot_money == 0:
            print("It took " + str(roll_number) + " rolls to break you.")
            print("The maximum amount of money in the pot was ${}".format(max_pot))

    if pot_money > max_pot:
        max_pot = pot_money

    print("The pot currently holds: $" + str(pot_money))
    die1 = random.randint(1,6)
    die2 = random.randint(1,6)

возвращает

Welcome to Lucky Sevens! Take your chances and win big if the die equal to 7! There are many ways to win!
Enter your bet: 2
Die 1 was 3 and die 2 was 2
The total of the die was: 5
You are currently on roll 1
The pot currently holds: $1.0
Die 1 was 3 and die 2 was 6
The total of the die was: 9
You are currently on roll 2
It took 2 rolls to break you.
The maximum amount of money in the pot was $2.0
The pot currently holds: $0.0
...