[Python] How do I check the value of a variable in python? [closed]

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I am a beginner in python and am making a Yahtzee game. I need to add the different dice variables with values of one together to get the score but I don't know how. For example. if dice1 was 1 and dice3 was also one, I want my code to check for that and add them together for the score. The roll function rolls the 5 die for a number and prints the values. The reroll function checks which die you want to reroll and changes their value to a random number. The choose variable is to check if the player has ended their turn or they have used up all 3 turns. The rolled variable is to check if the player has all ready rolled and so that the dice don't always change values. Please give any info you can.

    import random

    def roll():
    global rolled
    global dice1
    global dice2
    global dice3
    global dice4
    global dice5
    if rolled == False:
    dice1 = random.randint(1,6)
    dice2 = random.randint(1,6)
    dice3 = random.randint(1,6)
    dice4 = random.randint(1,6)
    dice5 = random.randint(1,6)
    rolled = True
    print("Dice 1:", dice1)
    print("Dice 2:", dice2)
    print("Dice 3:", dice3)
    print("Dice 4:", dice4)
    print("Dice 5:", dice5)
    print("")


    def reroll():
    global dice1
    global dice2
    global dice3
    global dice4
    global dice5
    dice_choice = input("Which dice do you want to roll again? ")
    if "1" in dice_choice:
    dice1 = random.randint(1,6)
    elif "2" in dice_choice:
    dice2 = random.randint(1,6)
    elif "3" in dice_choice:
    dice3 = random.randint(1,6)
    elif "4" in dice_choice:
    dice4 = random.randint(1,6)
    elif "5" in dice_choice:
    dice5 = random.randint(1,6)
    else:
    global choose
    choose = True

    def choice():
    print()
    print("Option 1: 1")
    print("Option 2: 2")
    print("Option 3: 3")
    print("Option 4: 4")
    print("Option 5: 5")
    print("Option 6: 6")
    print("Option 7: ")
    print("Option 8: ")
    print("Option 9: ")
    print("Option 10: ★")
    print("Option 11: ★★★★★")
    option = input(print("Select your option"))
    if option == "1":
    score =
    global choose
    choose = False

    def main():
    while True:
    for i in range(3):
    roll()
    reroll()
    global choose
    if choose == True:
    break
    global rolled
    rolled = False
    choose = True
    if choose == True:
    choice()

    global choose
    choose = False
    global rolled
    rolled = False
    main()

    Continue reading...

Compartilhe esta Página