python - Python 3 中的 def 函数语法错误

标签 python function python-3.x syntax-error

我正在自学编码,目前正在将掷骰子作为一个学习项目。我现在遇到了一些奇怪的问题。我代码中的第四个“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/

相关文章:

Python3 制作一个列表,按一定量递增,按一定量递减

python - 在 Python 中将整数列表转换为字节数组

python - 使用 PyPDF2 为 pdf 页面添加边距

c++ - 标准第 6.8 节中的这个示例如何工作?

php - 将 MySQL 查询包装在 PHP 函数中

python - 无法模拟打开,即使使用文档中的示例也是如此

python - 查找条件为真的第一个列表元素

python - python中for循环内的递归调用不会在预期的位置退出

python - 对 Pandas 系列进行算术运算以创建新系列

javascript - 试图移动一个 div 但得到 "outerhtml is not a function"