我无法使下列各项发挥作用。我需要通过添加
else:
print("Type only 4, 6, or 12.")
但是,对代码执行此操作不起作用:
def dicegame():
#This defines the dicegame coding so I can call it later on
number=int(input("Hello. Enter either 4,6 or 12 to determine what sided dice you want to use "))
import random
if number=="4" or "6" or "12":
print("You have rolled a", number, "sided dice with the number", random.randint(1,number))
#These if loops direct the program to the correct coding down to what the user inputs (ie. 4, 6 or 12)
print("Would you like to roll again?")
answer=input("Enter either yes or no.")
if answer == ("yes"):
dicegame()
if answer == ("no"):
print("Ok, goodbye")
#Program prints "Would you like to roll again?
#Using input, user can reply to what the program prints, labelled with the variable 'answer'
dicegame()
为我的验证添加else循环后,循环将中断。你知道吗
试试看
或者
“6”总是正确的-所以你总是满足条件。。。 由于要编写
number=int(...)
,还必须删除引号。你知道吗我看不到循环,但有一点是错的:
而不是
使用
注意这个数字已经被转换成
int
相关问题 更多 >
编程相关推荐