Python Forum
randint stops changing values in a loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
randint stops changing values in a loop
#1
hi! i have a problem i can't understand, randint stops popping new randdom values even if the variables are in the loop:
def pvp():
    dicesonboard = []
    dicesused = []
    dicesonship = []
    dicesremaining = []
    socres = {}
    rounds = 0
    print("if you want to quit type quit")
    while rounds < 3:
        dice1 = randint(1, 6)
        dice2 = randint(1, 6)
        dice3 = randint(1, 6)
        dice4 = randint(1, 6)
        dice5 = randint(1, 6)
        dice6 = randint(1, 6)
        userinput = input("to start the game type throw: ").lower()
        rounds += 1
        if userinput == "quit":
            break
        if userinput == "throw":
            print("let the game begin")
            print("Round", rounds)
            dices = [dice1, dice2, dice3, dice4, dice5, dice6]
            print("Thrown Dices:  ""Dice I: ", dice1, "Dice II: ", dice2, "Dice III: ", dice3, "Dice IV: ", dice4,
                  "Dice V: ", dice5, "Dice VI: ", dice6)
            if 6 not in dicesonship:
                if 6 in dices:
                    print("you have a ship now gather a captain and a crew")
                    for i in dices:
                        if i == 6:
                            dicesonship.append(i)
                            dicesused.append(randint(1, 6))
                            break
as you can see, i did put ranind inside of an append fund while looping but the value stays the same
Error:
Round 1 Thrown Dices: Dice I: 6 Dice II: 6 Dice III: 6 Dice IV: 1 Dice V: 2 Dice VI: 6 you have a ship now gather a captain and a crew [5] [6] to start the game type throw: throw let the game begin Round 2 Thrown Dices: Dice I: 3 Dice II: 6 Dice III: 4 Dice IV: 5 Dice V: 1 Dice VI: 1 [5] [6] to start the game type throw: throw let the game begin Round 3 Thrown Dices: Dice I: 5 Dice II: 1 Dice III: 6 Dice IV: 6 Dice V: 3 Dice VI: 4 [5] [6]
focus on the list with the int 5 (don't care about the other list), i did try to change randint to the variables (dice1,2 etc) but that dosent work..

anyone can explain to me how does this work because i just don't get it, thank you!
Reply


Messages In This Thread
randint stops changing values in a loop - by Naito - Jan-28-2019, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pip stops waiting for python walker 6 1,105 Nov-28-2023, 06:55 PM
Last Post: walker
  random numbers, randint janeik 2 588 Nov-27-2023, 05:17 PM
Last Post: janeik
  Unexpected output while using random.randint with def terickson2367 1 542 Oct-24-2023, 05:56 AM
Last Post: buran
  Loop through values and compare edroche3rd 6 737 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,201 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 952 Nov-16-2022, 07:58 PM
Last Post: Winfried
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,540 Jul-27-2022, 08:50 PM
Last Post: rob101
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,245 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,949 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  How to add for loop values in variable paulo79 1 1,480 Mar-09-2022, 07:20 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020