Mar-28-2023, 08:00 AM
Greetings, Python community!
I hope you are doing well.
I recently started re-learning Python (I love it too much!). I'm in the lesson about conditionals, and I've come across something that has left me a little confused. I'm practicing with a code snippet that sends a message depending on user input; my question is about the elif conditional. The program works well if the input is greater than or equal to the
The code in question is shown below:

I hope you are doing well.

I recently started re-learning Python (I love it too much!). I'm in the lesson about conditionals, and I've come across something that has left me a little confused. I'm practicing with a code snippet that sends a message depending on user input; my question is about the elif conditional. The program works well if the input is greater than or equal to the
LIMIT NUMBER
or if the input is less than the LIMIT NUMBER
. The problem starts when the input is equal to 12; my intention is to display a message indicating that the number 12 was entered. However, for some reason, when this number is entered, the interpreter skips this statement and outputs the message equivalent to the input being greater than or equal to the LIMIT NUMBER
.The code in question is shown below:
LIMIT_NUMBER: int = 10 user_input = int(input("Please, enter a number: ")) if user_input >= LIMIT_NUMBER: print(f"Your number is greater or equal to {LIMIT_NUMBER}.") elif user_input == 12: # The line above is the product of my doubt. # Why elif is ignored even if user_input == 12? print("This line will be ignored by the interpreter.") else: print(f"Your number is smaller than {LIMIT_NUMBER}.")
Assuming that the number 12 was entered:
Output:Your number is greater or equal to 10.
The interpreter is omitting line 6, completely ignoring the elif statement even though the condition is met. I am quite puzzled. Is there something that I am ignoring or doing wrong? I have already done some research on several sites, but I can't find an answer to my question.

I think that would be my main question for the moment; I look forward to any answer. Thank you very much in advance, comrades!

- Carmazum