我有一个骰子程序我在python中工作,当我尝试做一个“else”语句时,它不起作用。
这是我的代码:
'''
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!")
我认为问题是当这种情况发生时代码接近尾声:
else:
print(Fore.RED + 'That isnt an option!")
我不知道发生了什么。每当我尝试输入不是“if”或“elif”的东西时,它只会使用D4骰子。请帮忙!
答案 0 :(得分:0)
我想我不需要说什么。
在python3 shell中:
>>> diceI = "D1"
>>> print(diceI == "D4" or "d4")
d4
>>> print(bool(diceI == "D4" or "d4"))
True