每次我输入 4、6 或 12 时它都不接受它。为什么?代码对我来说看起来不错。请告诉我如何纠正或改变什么。
import random
def roll_the_dice():
print("Roll The Dice")
print()
repeat = True
while repeat:
number_of_sides = input("Please select a dice with 4, 6 or 12 sides: ")
if (number_of_sides in [4,6,12] and len(number_of_sides) == 0 and
number_of_sides == int):
user_score = random.randint(1,number_of_sides)
print("{0} sided dice thrown, score {1}".format(
number_of_sides,user_score))
roll_again = input("Do you want to roll the dice again? ")
roll_again.lower()
if roll_again == "no":
print("Have a nice day")
repeat = False
elif len(roll_again) == 0:
print("Error please type 'yes' or 'no'")
roll_again = input("Do you want to roll the dice again? ")
else:
print("You have entered an incorrect value, please try again")
number_of_sides = input("Please select a dice with 4, 6 or 12 sides: ")