how to create a loop that will make sure that my dice can be rolled as many times as required?
here's my code as a start off.

import random

sim=input (“Which sided dice would you like to roll? You can choose a 4-sided dice, a 6-sided dice or a 12-sided dice.”)
if output=4
then print (“The 4-sided dice has rolled to”,dice)
elif output=6
then print (“The 6-sided dice has rolled to”,dice2)
elif output=12
then print (“The 12-sided dice has rolled to”,dice3)
else input (“Please input a number 4, 6 or 12”)

there are errors within my coding, but i am more concerned about creating the loop, thanks (:
please don't be harsh, im new to python

4 Years
Discussion Span
Last Post by sneekula

You can apply an endless while loop (with an exit condition) like this ...

import random

# optional, make string input work with Python2 or Python3
try: input = raw_input
except: pass

info = '''
Which sided dice would you like to roll? You can choose a
4-sided dice, a 6-sided dice or a 12-sided dice.
(Type 0 to exit the loop)

while True:
    dice = random.randrange(1,5)
    dice2 = random.randrange(1,7)
    dice3 = random.randrange(1,13)
    sides = int(input("Input number 4, 6 or 12 > "))
    if sides == 0:
        break  # exit the endless while loop
    elif sides == 4 :
        print("The 4-sided dice has rolled to", dice)
    elif sides == 6 :
        print("The 6-sided dice has rolled to", dice2)
    elif sides == 12:
        print("The 12-sided dice has rolled to", dice3)
        print("Please input a number 4, 6 or 12")

Study the example code closely so you learn.

Edited by vegaseat


thank you, but raw_input doesn't work for me... is there something else i can use?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.