Python Forum
random module in while loops
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random module in while loops
#1
Hello everyone.
im new to python , just started before few days and i tried to made a snakes and ladders game.
as you can see in the code below i want that the program will choose a random number between 1-6 untill a player will reach to step 100 and it will be over.
but when the loop is starting every player gets the same random number the program choose at the start of the loop and not different number.
what can i do to make it different number every time to each user?
sorry for my bad english.
import random
dice = random.randint(1,6)
user1 = input('Hello,What is user1 name?:')
user2 = input('And what is the other user name?:')
user3 = input('what the user3 name whould be:)?:')
u1step = int(0)
u2step = int(0)
u3step = int(0)
while u1step < 100 or u2step < 100 or u3step  < 100 :
   start = input('Whould you like to roll the dice?: Yes Or No')
   if start == 'yes' :
       u1jump = random.randint(1, 6)
       u2jump = random.randint(1, 6)
       u3jump = random.randint(1, 6)
       u1move = u1step + u1jump
       u1step = u1move
       u2move = u2step + u1jump
       u2step = u2move
       u3move = u3step + u1jump
       u3step = u3move
   elif start == 'no' :
       print('You have ended the game')
       print(user1, 'is currently on the', u1step)
       print(user2, 'is currently on the ', u2step)
       print(user3, 'is currently on the ', u3step)
       break
   if u1step >= 100 or u2step >= 100 or u3step >= 100 :
       print('We have a winner !')
   print(user1,'is currently on the', u1step)
   print(user2, 'is currently on the ', u2step )
   print(user3, 'is currently on the ', u3step)
Reply


Messages In This Thread
random module in while loops - by yuvalsaias - Feb-03-2017, 11:25 AM
RE: random module in while loops - by Larz60+ - Feb-03-2017, 11:33 AM
RE: random module in while loops - by Mekire - Feb-03-2017, 12:15 PM
RE: random module in while loops - by wavic - Feb-03-2017, 12:17 PM
RE: random module in while loops - by Mekire - Feb-03-2017, 12:21 PM
RE: random module in while loops - by wavic - Feb-03-2017, 01:50 PM
RE: random module in while loops - by yuvalsaias - Feb-03-2017, 12:41 PM
RE: random module in while loops - by snippsat - Feb-03-2017, 02:13 PM
RE: random module in while loops - by wavic - Feb-03-2017, 03:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  <while> cycle is not interrupted when using the <random>module ShityCoder 3 2,188 Sep-04-2020, 04:05 PM
Last Post: ShityCoder
  Some help with Classes and the random module please? :) AlluminumFoil 2 2,215 Jan-08-2020, 11:03 PM
Last Post: AlluminumFoil
  Can't Get Random Module! Pls Help! VictorVictus 1 7,184 Aug-24-2019, 10:20 AM
Last Post: snippsat
  Question about the Random Module Exsul 1 2,019 Mar-13-2019, 02:06 AM
Last Post: ichabod801
  Random module Python 3.6 daryl_uk 1 2,255 Oct-25-2018, 12:09 AM
Last Post: micseydel
  Random module works in idle but not terminal. ottowiser 3 5,545 Apr-11-2018, 10:59 PM
Last Post: ottowiser

Forum Jump:

User Panel Messages

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