Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 randint stops changing values in a loop Naito Silly Frenchman Posts: 25 Threads: 11 Joined: Jan 2019 Reputation: 1 Likes received: 2 #1 Jan-28-2019, 08:11 PM 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! SheeppOSU Minister of Silly Walks Posts: 345 Threads: 64 Joined: Feb 2018 Reputation: 10 Likes received: 39 #2 Jan-28-2019, 10:25 PM I don't know if this will solve the problem but I thought you have to import random and it should look like this ```import random def pvp(): dicesonboard = [] dicesused = [] dicesonship = [] dicesremaining = [] socres = {} rounds = 0 print("if you want to quit type quit") while rounds < 3: 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) dice6 = random.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``` Age Doesn't Matter, Your Passion Does - Shreya Jain woooee Minister of Silly Walks Posts: 453 Threads: 0 Joined: Feb 2018 Reputation: 33 Likes received: 36 #3 Jan-29-2019, 02:07 AM (This post was last modified: Jan-29-2019, 02:08 AM by woooee. Edited 3 times in total.) Obviously 6 is either not in dices, or is in dicesonship, which should be an empty list. Print to see. Naito Silly Frenchman Posts: 25 Threads: 11 Joined: Jan 2019 Reputation: 1 Likes received: 2 #4 Jan-29-2019, 07:10 PM well, that dosen't work, yes i printed the lists too see, what i have copied here is not the ful code, the 6 is in dicesonship but that's not the problem the problem is that the value of ranint is a constant and not random while looping in a while loop. perfringo Da Bishop Posts: 1,121 Threads: 5 Joined: Jun 2018 Reputation: 116 Likes received: 255 #5 Jan-30-2019, 08:15 AM (Jan-29-2019, 07:10 PM)Naito Wrote: the problem is that the value of ranint is a constant and not random while looping in a while loop. I could not replicate your problem: ```import random rounds = 0 while rounds < 3: 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) dice6 = random.randint(1, 6) print(dice1, dice2, dice3, dice4, dice5, dice6) rounds += 1 1 5 5 4 1 3 5 4 2 5 2 5 4 4 2 4 1 4 ``` I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post help with changing values in an excel sheet and saving to a new file Moneyman212 2 141 Nov-19-2019, 06:25 AM Last Post: Moneyman212 Inheriting, given number from randint is not working beLIEve 0 104 Oct-12-2019, 06:50 PM Last Post: beLIEve For loop prints strane values? colt 2 194 Sep-22-2019, 02:01 AM Last Post: ichabod801 same number everytime when using random.randint summeringpainting 5 394 Aug-23-2019, 11:01 AM Last Post: Malt Get all values of for loop with an index BollerwagenIng 2 308 Aug-09-2019, 07:58 AM Last Post: BollerwagenIng change array column values without loop khalidreemy 2 268 May-05-2019, 09:05 AM Last Post: DeaD_EyE First for loop stops after first iteration Divanova94 10 1,028 May-01-2019, 04:27 PM Last Post: buran file.write stops while true loop from executing in python3 boonr 3 413 Mar-25-2019, 12:50 PM Last Post: ichabod801 Python Thread stops execution neethuvp 1 382 Feb-18-2019, 06:36 PM Last Post: micseydel detect when scanner stops darter 1 526 Jun-29-2018, 10:07 PM Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)