1

I am a new to Python, and I ran into some issues when developing a D&D Dice program.

import random   

print("Hi,here you can roll all D´n´D Dice´s!")  
dice=input("What dice do u want?D4,D6,D8,D10,D12,D20 or D100?")  

if dice=="D4" or "d4":  
    print(random.randint(1,4))  
elif dice=="D6" or "d6":  
    print(random.randint(1,6))  
elif dice=="D8" or "d8":  
    print(random.randint(1,8))  
elif dice=="D10"or"d10":  
    print(random.randint(1,10))  
elif dice=="D12"or"d12":  
    print(random.randint(1,12))      
elif dice=="D20"or"d20":  
    print(random.randint(1,20))  
elif dice=="D100"or"d100":  
    print(random.randint(1,100))  
else: print("No?Ok!")  

When I run the program and enter the number of dice, it always enter the first if statement.

Patrice
  • 4,641
  • 9
  • 33
  • 43
  • Do you always get a number from 1 to 4 (as Baruchel's answer fixes), or do you always get the number 1? Also, what do you get if you enter invalid input (for example, `D3`?) – ASCIIThenANSI Sep 29 '15 at 19:50

1 Answers1

3

You want to write:

if dice=="D4" or dice=="d4":

instead of:

if dice=="D4" or "d4":

"d4" by itself has a (true) boolean value because it isn't an empty string.

Thomas Baruchel
  • 7,236
  • 2
  • 27
  • 46