import random # importing random to allow the random intger import time #importing time this is not needed but allows for the wait before restarting def start(): #This def allows the program to carry on running after each output print("Enter the number of faces you would like your die to have.") #Explaining what to input die = int(input("Choose from: 4, 6 or 12 ")) #input for the interger that we will work with if die == 4: #if the die == 4 then run this code for x in range(1): #for x means change x into the range of 1, run this code once. print(random.randint(1,4)) #select a random number between 1 and 4 time.sleep(1) #sleep for a second return start() #return back to the start elif die == 6: for x in range(1): print(random.randint(1,6)) #number between 1,6 time.sleep(1) return start() elif die == 12: for x in range(1): print(random.randint(1,12)) #between 1,12 time.sleep(1) return start() else: #if the number is not 4 6 or 12 then run this print("You have inputed the wrong number, please enter 4, 6 or 12.") #saying you have to choose a number between 4, 6 and 12 time.sleep(0.5) return start()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question