Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

python - Hello I was confused about this code because purely from a technical stand point it should work

This is supposed to take three int values, and give you the LOWEST amount

num1 = int(input())
num2 = int(input())
num3 = int(input())

if (num1 < num2) and (num1 < num3):
    print(num1)
elif num2 < num3
     print(num2)
else:
    print(num3)

I know it's messy and kinda hard to read but my point is when i put something like 7 15 3, it always outputs 15. Why?

question from:https://stackoverflow.com/questions/66055722/hello-i-was-confused-about-this-code-because-purely-from-a-technical-stand-point

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You were missing a colon after the elif. The code gives the expected answer:

num1 = int(input("Enter: "))
num2 = int(input("Enter: "))
num3 = int(input("Enter: "))

if (num1 < num2) and (num1 < num3):
    print(num1)
elif num2 < num3:
     print(num2)
else:
    print(num3)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...