Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop problems
#1
Hello everyone.
im new to python and im trying to make a snakes and ladder game code.
im having troubles as you can see at the code below with the 'for' loop.
its calculate the steps a player move each time he roll the dice but the current step he is at the end of the loop save it as the start step for the next player and than there is a situation when a player is on the 5th step and get to the 15th step in a turn when you can only jump from 1-6 steps a turn.
please tell me what im doing wrong and how can i fix that, thank you:)
sorry for my english as well if i have mistakes.

import random
num_of_user = int(input('how many players do you want?:'))
users = []
user_name = ''
for i in range(1, num_of_user+1):
   user_name = input ('what is the name of player' + str(i) +'?')
   users.append(user_name)
step = 0
while step < 100 :
   for user in users:
       start = input(user +  'Whould you like to roll the dice? Yes or No ')
       if start == 'yes' :
           dice = random.randint(1, 6)
           current_step = step + dice
           step = current_step
           print (user , 'is currently on step' , current_step)
Reply


Messages In This Thread
Loop problems - by yuvalsaias - Feb-04-2017, 01:33 PM
RE: Loop problems - by ichabod801 - Feb-04-2017, 04:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems with my loop python_student 3 1,559 Feb-17-2022, 09:49 PM
Last Post: deanhystad
  sports Stats > table output loop problems paulfearn100 3 2,526 Jul-22-2020, 03:21 AM
Last Post: c_rutherford
  Loop problems Kristenl2784 0 1,366 Jul-09-2020, 03:57 PM
Last Post: Kristenl2784
  “While” Loop Problems Ryan_teresi 3 2,936 Jun-27-2020, 06:43 PM
Last Post: tanv321

Forum Jump:

User Panel Messages

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