#------------------------------------------------------------------------------- # Name: Dice Simulator # Purpose: Example for testing purposes - errors included # # Author: Barnesr # # Created: 05/02/2015 # Copyright: (c) barnesr 2015 # Licence: Creative Commons #------------------------------------------------------------------------------- import random #Function, this function give a random number between 0 and sides def dice(sidesin): numin=random.randint(0,sidesin) return numin #Start of while loop, loop should repeat until q is entered quit='n' while quit=='n': #This code runs once in every loop #User input to select which dice - users should only be able to select one of these 4 sides=int(input('How many sides does your dice have, 4, 6, 12 or 24')) #Sends the number of sides to the dice function score=dice(sides) if sides ==4: #print score for a 4 sided dice print('You rolled a 4 sided dice and scored',score ) elif sides ==6: #print score for a 6 sided dice #why is this one different - what is the advantage? print('You rolled a dice with ',sides,' sides and scored ', score) elif sides ==12: #print score for a 12 sided dice print('you a 12 sided dice and scored ',score ) elif sides ==24: #print score for a 12 sided dice print('You rolled a 12 sided dice and scored ',Score ) else: #Error message if you choose a dice that is not an option print('You rolled a ',sides,' sided dice and scored ', score) #code to allow user to chose to continue or quit quit=input('press enter to continue or q to quit: ')
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