If-else 无效语法

问题描述 投票:0回答:1
a = input("enter the first age ")
print(a)
b = input("enter the seond age ")
pint(b)
c = input("enter the third age ")
print(c)
if (a != b and a != c and b != c):
    {
        if (a>b and a>c):
        print ("a is the largest")
        if (b>a and b>c):
        print ("b is the largest")
        else: 
        print ("c is the largest")
    }
else: 
    print ("please enter distinct digits")

编译器说第 9 行“语法无效”。请告诉我。

之前我写的是 if() 所以我给了空间 if () 我相信缩进是正确的。

python if-statement
1个回答
0
投票

括号不是你麻烦的根源,尽管它们是无关的。大括号是。您还需要正确缩进内部条件。

a = input("enter the first age ")
print(a)

b = input("enter the seond age ")
print(b)

c = input("enter the third age ")
print(c)

if a != b and a != c and b != c:
    if a > b and a > c:
        print("a is the largest")
    if b > a and b > c:
        print("b is the largest")
    else: 
        print("c is the largest")
else: 
    print("please enter distinct digits")
© www.soinside.com 2019 - 2024. All rights reserved.