我写了一个程序来模拟掷骰子的掷骰子。但是在运行程序之后,它总是在每一行之后都不显示。有人可以帮我吗 ?
import random
#Function That Simulates Dice Roll
def dice_roll():
while True:
print()
question = (input(print("Do you want to roll the dice ? (Y/N)")))
print()
if question == 'Y' or question == 'y':
name = input(print("Enter your name"))
print()
print(name + ":")
print()
num = random.randint(1, 7)
print("The Dice rolls and The number is " + " " + str(num))
elif question == 'N' or question == 'n':
print("OK")
print("Exiting The Program")
print("Have a nice day :-)")
break
#Above Function Gets Called
dice_roll()
答案 0 :(得分:0)
请勿将print
放入input
来电。
question = (input(print("Do you want to roll the dice ? (Y/N)")))
你在这里做的是调用print
(打印你的消息),并将print的返回值(None
)传递给input
,它将它用作提示符输入。因此,每当您要求输入时,您都会打印None
。
如果你有
question = input("Do you want to roll the dice ? (Y/N)")
这就足够了。