-1

Hi I have been trying to write a dice rolling program and I just got this error can you tell me whats wrong with my code and offer me a solution to fix it? Thanks.

import random
while True:
    dice_type = int(input("would you like to roll a 4,6 or 12 sided dice"))
    if dice_type in[4,6 or 12]:
                    break
                print("Sorry that is not the correct input")

                score = random.randint(1, dice_type)

                print ("The dice you threw was a %d-sided dice" %dice_type)
                print ("You rolled a %d" %score)

update:

Ok I have tweaked the program so that it looks like this...

import random
while True:
    dice_type = int(input("would you like to roll a 4,6 or 12 sided dice:"))

    score = random.randint(1, dice_type)
    print ("The dice you threw was a %d-sided dice" %dice_type)
    print ("You rolled a %d" %score)

It now works. thanks for the quick responses everyone. if you have found a way to make the program reject incorrect values being entered please comment a solution.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Does this answer your question? [I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it) – Karl Knechtel Jul 14 '23 at 19:25

1 Answers1

0

It looks like your indentation is wrong. Try this.

import random
while True:
    dice_type = int(input("would you like to roll a 4,6 or 12 sided dice"))
    if dice_type in [4, 6, 12]: # you also dont need that or
        break
    print("Sorry that is not the correct input")

score = random.randint(1, dice_type)

print ("The dice you threw was a %d-sided dice" %dice_type)
print ("You rolled a %d" %score)
jramirez
  • 8,537
  • 7
  • 33
  • 46
  • Thanks for the quick response. I am no longer getting the indentation error however when i input the type of dice i would like to use nothing happens. – Jack_Harwood Nov 19 '13 at 21:47
  • Perhaps the `score = ...` line and the ones after it should be de-dented one more level so that they're not considered part of the `while` loop... – twalberg Nov 19 '13 at 21:51