0

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....

1
  • That's because you didn't re assigned the y after increasing. change it to y=y+1 Commented Jan 29, 2016 at 12:20

3 Answers 3

1

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)

Sign up to request clarification or add additional context in comments.

5 Comments

We have all been there once ;-) - please mark the answer as accepted (which will also give you some so-points)
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.
what about adding print(y) ?
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]
Of cource, when you've found and corrected the bug, you remove the debugging output.
1

You need to put y+=1 or y=y+1 at the end of the while.

Comments

0

Instead of this y+1 you have to do this y = y+1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.