I'm pretty new to python. I wrote this to emulate rolling dice;
dsides = int(input("how many sides do your dice have?"))
print("Your dice has " + str(dsides) +" sides")
dint = int(input("How many dice do you want to roll?"))
print("You are rolling " + str(dint) + " dice")
import random
y=0
while( y < dint ):
out = random.randint(1, int(dsides))
print(str(out))
y+1
the problem is the while loop doesn't stop looping on integer 'dint' quantity....
Wai Ha Lee
8,856102 gold badges61 silver badges100 bronze badges
3 Answers 3
The last line should read
y=y+1
Now it is not doing anything to y.
(A general tip for debugging: If your loop does not terminate, print out the loop value to see what is happening to it)
answered Jan 29, 2016 at 12:19
MortenSickel
2,2095 gold badges28 silver badges48 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
MortenSickel
We have all been there once ;-) - please mark the answer as accepted (which will also give you some so-points)
Obiehakerman
The problem debugging for me is that I can only do it via code. I'm coding at college and due to admin rights etc I can only use online consoles which never seem to include debugs.... So I knew the loop was stuck in a loop because it wasn't returning anything.
MortenSickel
what about adding print(y) ?
Obiehakerman
Well I'm attempting to have it print a separate variable so that the output looks like this; Rolls: 3 - 2 - 5 -3 but I'm not to sure how to do that, don't know how to turn 'dint' into a numbered array, for instance if 'dint' = 4 I want an array 'arrrolls' = [1, 2 , 3, 4]
MortenSickel
Of cource, when you've found and corrected the bug, you remove the debugging output.
You need to put y+=1 or y=y+1 at the end of the while.
Comments
Instead of this y+1 you have to do this y = y+1
answered Jan 29, 2016 at 12:19
paulo_ferreira
831 silver badge7 bronze badges
Comments
lang-py
yafter increasing. change it toy=y+1