import random

while True:
dice = random.randrange(1,5)
dice2 = random.randrange(1,7)
dice3 = random.randrange(1,13)
sides = int(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. Type 0 to exit the loop.")

if sides ==0:
break
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)
else:
print ("Please input a number 4, 6 or 12")

This is my fully working code. I am just stuck on my pseudo code and algorithm for this coding.
Here is a quick summary of what is going on in the code:
The user gets to choose between a 4, 6 or 12 sided dice. When the user chooses an option, they can repeat the process as many times as necessary or choose to exit the loop.

Your 7th line has an error. You need to convert the output of the input function to int. Not the input function itself.
It is an over kill to calculate all the diceroll for all the possible inputs. It is enough to calculate it after the input.
No need for …

I do not know a standard for pseudo code. I have read this, and became not smarter.

For a natural language pseaudo code I would write:

asktext = Which sided dice would you like to roll? You can …

All 7 Replies

Your 7th line has an error. You need to convert the output of the input function to int. Not the input function itself.
It is an over kill to calculate all the diceroll for all the possible inputs. It is enough to calculate it after the input.
No need for so much elifs...
Randrange is overkill for this...

I fixed this for you:

import random
while True:
sides = int(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. Type 0 to exit the loop."))
if sides==0:
break
if sides not in (4,6,12):
print("Please input a number 4, 6 or 12")
continue
rolled = random.randint(1,sides)
print ("The %s-sided dice has rolled to %s" % (sides,rolled))

thanks, what about the pseudo code and algorithm??

I do not know a standard for pseudo code. I have read this, and became not smarter.

For a natural language pseaudo code I would write:

asktext = 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.
printouttext="The %s-sided dice has rolled to %s"
infinite loop:
ask the user which dice to roll with asktext
convert the aswer to integer, store it in sides
if sides is 0, then exit the loop
if sides not one of 4,6,12, then continue the loop
make a random integer between 1 and sides, store it in rolled.
print out printouttext with sides and rolled substituted

Actually, I don't know any standards for pseudo-code except possibly for BNF (Backus–Naur Form) which is used for many standards, including the DDN Whitebook specification of the TCP/IP protocols.

what about the algorithm?

what about the algorithm?

Hey man ...

promptText = "blablabla..."

TopOfLoop:
input = getInput( withPromptText )
if( ! valid( input ) ) goto TopOfLoop
if( input == quit ) goto Stop
getResultForInputAndShow( input );
goto TopOfLoop

Stop:

Thanks so much, I finally understand!!!