如何修复:我的第二个if语句出现语法错误,我不知道为什么?

2024-06-16 14:42:07 发布

您现在位置:Python中文网/ 问答频道 /正文

问题是python告诉我第二个if语句的语法是错误的,我不知道为什么。。。 不要介意有些代码是丹麦语的

我试图重做整个代码,但结果相同

import math

x = float(input("Indtast 1 for trekant eller 2 for cirkel: "))

if (x == 1):
    a = float(input("Indtast side a: "))
    b = float(input("Indtast side b: "))
    c = float(input("Indtast side c: "))

    s = (1/2) * (a + b + c)
    areal = math.sqrt(s * (s - a) * (s - b) * (s - c))

    print("")
    print("Arealet er " + str(areal)

if (x == 2):
    pi = 3.14
    radius = float(input("indtast radius "))
    omkreds = radius * 2 * pi
    areal = radius * radius * pi

    print("")
    print("Det er arealet", areal)
    print("")
    print("Det er omkredsen", omkreds)

else:
    print("")
    print("KÆMPE FAIL! KA' DU IK' LÆSE!")

我原以为代码运行时不会出现任何故障,但这里的情况似乎并非如此


Tags: 代码forinputifpimathfloatside