由于输入,换行符列表中代码的语法错误,如何调整? [关闭]

问题描述 投票:-6回答:4

在输入和列表之间的多行代码中也出现语法错误。


    Import math 
    o = " What operation do you want to use :\n\

    1. Add\n\ 
    2. Subtract\n\
    3. Multiply\n\
    4. Divide\n\
    5. Square the first number\n\
    6. Square the second number\n\
    7. Calculate the power of the first number to the second number\n\
    8. Square root the first number\n\
    9. Square root the second number\n\"

    n1 = int(input(" Enter the first number: "))

    n2 = int(input(" Enter the second number: "))

    print(o) 

    oc = int(input("Enter the operation you have chose:"))

    if oc == 1: 
     print(n1 + n2)

    elif oc == 2:
        print (n1 - n2)

    elif oc == 3:
        print(n1 * n2)

    elif oc == 4:
        print(n1 / n2)

    elif oc == 5:
        print(n1**2)

    elif oc == 6:
        print(n2*2)
```this does not work properly```
    elif oc == 7:
        print(n1**n2)

    elif oc == 8:
        print(math.sqrt(n1))

    elif oc == 9:
        print(math.sqrt(n2))

代码无法正确处理输入,使用数组或列表会更容易。甚至使用numpy并使用文本文件。怎么会>

在输入和列表之间的多行代码中也出现语法错误。 Import math o =“您要使用什么运算:\ n \ 1.加\ n \ 2.减\ n \ 3.乘\ n \ ...

python python-3.x helper
4个回答
3
投票

Python中的多行字符串由'''分隔。


0
投票

您在此行的末尾留下了额外的\


0
投票

除了多行字符串(以'''代替''开头,其他都没问题。现在,您应该尝试减少代码行。您将在优化工作脚本时学习。


0
投票

如果要使用多行字符串,也应该使用三个引号,以使换行符只是\ n。希望我能提供帮助。

© www.soinside.com 2019 - 2024. All rights reserved.