【发布时间】:2015-12-07 06:34:39
【问题描述】:
输入和列表之间的多行代码也存在语法错误。
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 并使用文本文件。怎么会
【问题讨论】:
-
在我的代码中,打印的顺序也是正确的
-
只看代码格式化程序完成的文本着色,看起来你在某处有一个未终止的字符串常量。你需要一个额外的引号!
标签: python python-3.x helper