出于某种原因,我的脚本拒绝直接从 Text Wrangler 运行,但在导入终端时工作正常。
import math
def main():
print("This program find the real solutions to a quadratic\n")
a,b,c, = eval(input("Please enter the coefficients (a,b,c): "))
discRoot = math.sqrt(b * b -4 * a * c)
root1 = (-b + discRoot) / (2 * a)
root2 = (-b - discRoot) / (2 * a)
print("\nThe solutions are:" , root1, root2)
main()
当我在 textwrangler 中运行它时,我收到错误消息“TypeError: eval() arg 1 must be a string or code object”。使用 eval() 是否意味着以下输入是整数而不是字符串?为什么会这样?