Python赢得了';t运行我的项目-有人想检查我的代码吗?

Python赢得了';t运行我的项目-有人想检查我的代码吗?,python,project,Python,Project,从我的第一个项目开始,一个解决不同数学问题的计算器。在这个阶段,它只执行毕达哥拉定理(它可以选择计算斜边或另一侧)。还有一个转换温度的选项,尽管实际代码尚未实现。 我尝试用最新版本的python运行代码,它会在瞬间打开然后关闭。我知道这意味着代码中有错误。因为我是新手,我经常出错,我很难发现自己的错误。 如果有人想看,这是我的代码。感谢您的反馈,我很乐意回答您的任何问题 option = input("1. Pythagora's Theorem 2. Tempurature Conv

从我的第一个项目开始,一个解决不同数学问题的计算器。在这个阶段,它只执行毕达哥拉定理(它可以选择计算斜边或另一侧)。还有一个转换温度的选项,尽管实际代码尚未实现。 我尝试用最新版本的python运行代码,它会在瞬间打开然后关闭。我知道这意味着代码中有错误。因为我是新手,我经常出错,我很难发现自己的错误。 如果有人想看,这是我的代码。感谢您的反馈,我很乐意回答您的任何问题

option = input("1. Pythagora's Theorem 2. Tempurature Conversions")
option = int(option)
if option == 1:
 op = input("1. Calculate the length of the hypotenuse 2. Calculate the length of another side")
 op = int(op)
  if op == 1:
   a = input("Enter the length of side a: ")
   b = input("Enter the length of side b: ")
   a = int(a)
   b = int(b)
   c = a*a + b*b
   print(c)
   print ("Answer is in surd form.")
  if option == 2:
   a = input("Enter the length of side a: ")
   hyp = input("Enter the length of the hypotenuse: ")
   a = int(a)
   hyp = int(hyp)
   b = hyp*hyp - a*a
   print(b)
   print("Answer is in surd form.")
  else:
   print("That is not a valid option. Enter a valid option number.")
else: ("That is not a valid option. Eneter a valid option number.")
编辑:它是固定的,问题是缺少“)”和可能我的奇怪缩进。现在一切都很好,谢谢你的帮助,这让学习变得容易多了

您在线路上丢失了一个“)”


您没有遵循正确的缩进,并且犯了一个逻辑错误

option = input("1. Pythagora's Theorem 2. Tempurature Conversions > ")
option = int(option)
if option == 1:
    op = input("1. Calculate the length of the hypotenuse 2. Calculate the length of another side > ")
    op = int(op)
    if op == 1:
        a = input("Enter the length of side a: ")
        b = input("Enter the length of side b: ")
        a = int(a)
        b = int(b)
        c = a*a + b*b
        print(c)
        print ("Answer is in surd form.")
    elif op == 2:
        a = input("Enter the length of side a: ")
        hyp = input("Enter the length of the hypotenuse: ")
        a = int(a)
        hyp = int(hyp)
        b = hyp*hyp - a*a
        print(b)
        print("Answer is in surd form.")
    else:
        print("That is not a valid option. Enter a valid option number.")
elif option == 2:
    print("You havent programmed it")
else:
    print("That is not a valid option. Eneter a valid option number.")

python解释器实际上应该给您反馈。直接从终端运行python,这样程序就不会关闭

以下是您的代码的固定版本:

option = input("1. Pythagora's Theorem 2. Tempurature Conversions")
option = int(option)
if option == 1:
    op = input("1. Calculate the length of the hypotenuse 2. Calculate the length of another side")
    op = int(op)
    if op == 1:
        a = input("Enter the length of side a: ")
        b = input("Enter the length of side b: ")
        a = int(a)
        b = int(b)
        c = a*a + b*b
        print(c)
        print ("Answer is in surd form.")
    elif op == 2:
        a = input("Enter the length of side a: ")
        hyp = input("Enter the length of the hypotenuse: ")
        a = int(a)
        hyp = int(hyp)
        b = hyp*hyp - a*a
        print(b)
        print("Answer is in surd form.")
    else:
        print("That is not a valid option number.")

请注意,大多数程序员使用4个空格缩进代码。

Python脚本应该在终端中运行。您是否在终端中运行了诸如“python”之类的命令?请注意,在这里提问之前,我们希望您识别代码中的特定问题,并将其减少到在不进行更改的情况下运行时产生该特定问题的最短时间。如果你要求其他人试着找出问题所在,那么在询问之前还有很多事情要做。另请参见Python中的空格(缩进)问题。把它做好。如果缩进不正确,请输入
。还有,你最后的指纹丢失了。。。a
打印
。应该换一条新线路。还有更多的问题,但当它最终运行时,您将对其进行管理。是的,只是修复了它,谢谢。虽然仍然不起作用,但它很有帮助。在结尾附近的多余的“````”,我认为是从某处复制代码留下的工件。代码应该在删除后运行。您会发现,忘记右括号是最常见的编程错误之一。发生这种情况时,编译器将在某某行报告一个错误,但在该行中编译器意识到缺少右括号。实际错误与前面的行一致。因此,一个方便的提示是,每当你在给定的线路上出现错误,并且线路看起来很好时,请检查线路。你可能忘了一个括号,或者类似的东西。这个“```是放在这里的,我想我需要它。
option = input("1. Pythagora's Theorem 2. Tempurature Conversions")
option = int(option)
if option == 1:
    op = input("1. Calculate the length of the hypotenuse 2. Calculate the length of another side")
    op = int(op)
    if op == 1:
        a = input("Enter the length of side a: ")
        b = input("Enter the length of side b: ")
        a = int(a)
        b = int(b)
        c = a*a + b*b
        print(c)
        print ("Answer is in surd form.")
    elif op == 2:
        a = input("Enter the length of side a: ")
        hyp = input("Enter the length of the hypotenuse: ")
        a = int(a)
        hyp = int(hyp)
        b = hyp*hyp - a*a
        print(b)
        print("Answer is in surd form.")
    else:
        print("That is not a valid option number.")