0

I have a dice program I'm working on in python and when I try and do an "else" statement it doesn't work.

Here's my code:

'''
Made by Thou
http://v.ht/Thou
'''

import os
import time
from random import *
from colorama import *

os.system('cls') # Clears the screen

print(Fore.RED + 'Made by Thou') 
print(Fore.RED + '@Th0u__')

print() # Blank line

print(Fore.WHITE + 'What dice would you like to roll?')

print("D4, D6, D10, D12, D20")

D4 = randint(1, 4) # Normal definition

D6 = randint(1, 6) # Normal definition

D10 = randint(1, 10) # Normal definition

D12 = randint(1, 12) # Normal definition

D20 = randint(1, 20) # Normal definition

age = D4 # Normal definition

diceI = input(":") # The thing that shows ':'

# Messy code woo

if diceI == "D4" or "d4": 
    time.sleep(.1)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.3)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.5)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.7)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 4))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 4)) 

elif diceI == "D6" or "d6": 
    time.sleep(.1)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.3)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.5)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.7)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 6))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 6)) 

elif diceI == "D10" or "d10": 
    time.sleep(.1)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.3)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.5)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.7)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 10))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 10)) 

elif diceI == "D12" or "d12": 
    time.sleep(.1)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.3)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.5)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.7)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 12))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 12)) 

elif diceI == "D20" or "d20": 
    time.sleep(.1)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.2)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.3)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.4)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.5)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.6)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.7)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 20))
    time.sleep(.8)
    os.system('cls')
    print(randint(1, 20)) 

else:
    print(Fore.RED + 'That isnt an option!")

I think the problem is the code is near the end when this happens:

else:
    print(Fore.RED + 'That isnt an option!")

I have no idea what's going on. Whenever I try to type something that wasn't if the "if"s or "elif"s it just uses the D4 dice. Please help!

Thou
  • 1
  • 1
  • 1
    The problem is nothing to do with `else` or `elif`; it's with `diceI == "D4" or "d4"`. We'll find you a duplicate question with a good answer, but the short version is that you want `diceI in {"D4", "d4"}` or `diceI.lower() == 'd4'` here. – abarnert Apr 24 '18 at 02:30
  • You could really have trimmed this down. Next time please try to post a [mcve]. Thanks! – Neuron Apr 24 '18 at 02:39
  • In the else print statement, use only either single quotes or double quotes. print(Fore.RED + "That isnt an option!") – DxTx Apr 24 '18 at 02:44

1 Answers1

0

I think i needn't say anything.

In python3 shell:

>>> diceI = "D1"
>>> print(diceI == "D4" or "d4")
d4
>>> print(bool(diceI == "D4" or "d4"))
True
  • I think you could actually say quite a lot. Why does this produce `d4`? – Neuron Apr 24 '18 at 02:40
  • `diceI == "D4" or "d4"` equivalent to `False or "d4"`. Since first condition is `False`, it returns the second condition, which is `'d4'`. – Frank Apr 24 '18 at 02:58
  • Yes, @Frank is said right.And string type equivalent Flase when it is None or empty string. – jihong chen Apr 24 '18 at 03:09