我正在自学编码,目前正在将掷骰子作为一个学习项目。我现在遇到了一些奇怪的问题。我代码中的第四个“def”,无论它实际上是什么(我已经尝试过几个都可以单独工作)它总是被标记为语法错误。这是我拥有的:
import random
def mult():
print('How many dice would you like to roll?')
multiplier = input()
mod()
def mod():
print('What modifier, if any, would you like to assign?')
modifier = input()
result()
def result():
total = (roll * multiplier) + modifier
print('Your result is'
(str(total)
def menuscreen():
print("Welcome to Jack's dice roller. What kind of die would you like to roll?")
print("")
print("A. d2")
print("B. d4")
print("C. d6")
print("D. d8")
print("E. d10")
print("F. d12")
print("G. d20")
print("H. d100")
def gen():
menuscreen()
if input() == 'a' or 'A':
roll = random.randint(1,2)
mult()
if input() == 'b' or 'B':
roll = random.randint(1,4)
mult()
if input() == 'c' or 'C':
roll = random.randint(1,6)
mult()
if input() == 'd' or 'D':
roll = random.randint(1,8)
mult()
if input() == 'e' or 'E':
roll = random.randint(1,10)
mult()
if input() == 'f' or 'F':
roll = random.randint(1,12)
mult()
if input() == 'g' or 'G':
roll = random.randint(1,20)
mult()
if input() == 'h' or 'H':
roll = random.randint(1,100)
mult()
def queryque():
print('Would you care to roll again?')
if input == 'yes':
gen()
if input == 'no':
end
gen()
最佳答案
看起来您在 result()
定义的末尾缺少两个右括号。你可能想要这样的东西:
def result():
total = (roll * multiplier) + modifier
print('Your result is ' + str(total))
关于python - Python 3 中的 def 函数语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29690663/