pycharm 每当我运行这段代码时,python中不会弹出任何值[duplicate]

x759pob2  于 2022-11-08  发布在  PyCharm
关注(0)|答案(1)|浏览(122)

此问题在此处已有答案

print statement inside of input returns with a "none"(1个答案)
关闭4个月前.

import random

print("Dice Roll!")

while True:
    roll = random.choice (range (1, 7)) print(f" (roll) came up!")
    x = input(print("Roll dice again? (Y/N): ")).Lower()

    if x != "y":
        exit(0)
kninwzqo

kninwzqo1#

这里你必须在格式化文本中使用{roll} insted(roll)
不要在输入中使用print。你必须只传递字符串。

import random
print("Dice Roll!")
while True:
    roll = random.choice (range (1, 7)) 
    print(f" {roll} came up!")
    x = input("Roll dice again? (Y/N): ").Lower()
    if x != "y":
        exit(0)

相关问题