In python "else if" is spelled "elif".
Also, you need a colon after the elif and the else.

Simple answer to a simple question. I had the same problem, when I first started (in the last couple of weeks).

So your code should read:

def function(a):
    if a == '1':
        print('1a')
    elif a == '2':
        print('2a')
    else:
        print('3a')

function(input('input:'))
Answer from Frames Catherine White on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_conditions.asp
Python If Statement
Python can evaluate many types of values as True or False in an if statement. Zero (0), empty strings (""), None, and empty collections are treated as False. Everything else is treated as True.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ if-elif-else
Python if, if...else Statement (With Examples)
number = 5 # outer if statement if number >= 0: # inner if statement if number == 0: print('Number is 0') # inner else statement else: print('Number is positive') # outer else statement else: print('Number is negative') ... Here's how this program works. ... In certain situations, the if statement ...
Discussions

python - What is the correct syntax for 'else if'? - Stack Overflow
Your first example can be written as print d.get(a, "3a") 2013-05-31T10:19:38.1Z+00:00 ... As you can see, else if should be changed to elif, there should be colons after '2' and else, there should be a new line after the else statement, and close the space between print and the parentheses. ... Winston C. Yang ยท 1,50722 gold badges1818 silver badges2727 bronze badges ... Dan D. Over a year ago ยท python ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Putting a simple if-then-else statement on one line - Stack Overflow
How do I write an if-then-else statement in Python so that it fits on one line? For example, I want a one line version of: if count == N: count = 0 else: count = N + 1 In Objective-C, I wo... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Input in if/else statements
I am a new programmer, I donโ€™t really know what I am doing that well, but I was sitting in class, and I thought to myself: hmm, can you put an input in an if-else statement?" and asked my professor, and he said that he has never thought about or tried doing this before. More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
December 15, 2023
Python IF-Else-Elif with real Example
๐ŸŒ r/PythonLearning
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-if-else
Python If Else Statements - Conditional Statements - GeeksforGeeks
September 16, 2025 - if-elif-else statement in Python is used for multi-way decision-making. This allows us to check multiple conditions sequentially and execute a specific block of code when a condition is True.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ controlflow.html
4. More Control Flow Tools โ€” Python 3.14.3 documentation
Of course, other ways of ending ... searches for prime numbers: >>> for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ......
๐ŸŒ
Lawrence
www2.lawrence.edu โ€บ fast โ€บ GREGGJ โ€บ CMSC210 โ€บ loops โ€บ if-else.html
Input and if-else
Here is an example of how this works. Suppose we entered 87 cents. ... After handing out the quarters, we have 87 - 3*25 = 12 or 87% = 12 cents left to hand out. ... After handing out the dime, we have 12 - 1*10 = 2 or 12 = 2 cents left to hand out. ... Finally, we hand out the 2 cents as ...
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ python-if-else-statements.php
Python if elif else
September 20, 2024 - ... If the expression is True, the statements after if are executed; otherwise, the statements after else are executed. In the following example the program will print the second print statement as the value of a is 10.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ if-else-statements-in-python
How to Use If/Else Statements in Python: A Beginnerโ€™s Guide | DigitalOcean
March 7, 2025 - This Python tutorial provides steps on using if/else statements, covering syntax, multiple conditions, nested statements, common mistakes, and the best practices.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_if_else.htm
Python if-else Statement
Now, let's see the Python implementation the above flowchart. age=25 print ("age: ", age) if age >=18: print ("eligible to vote") else: print ("not eligible to vote") On executing this code, you will get the following output โˆ’ ... To test ...
๐ŸŒ
Dataquest
dataquest.io โ€บ blog โ€บ tutorial-using-if-statements-in-python
How to Use IF Statements in Python (if, else, elif, and more) โ€“ Dataquest
November 24, 2024 - ... # What if the condition is met? x = 3 y = 10 if x < y: print("x is smaller than y.") else: print("x is greater than y.") ... In this case, Python just prints out the first sentence as before.
๐ŸŒ
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu โ€บ notebooks โ€บ chapter04.01-If-Else-Statements.html
If-Else Statements โ€” Python Numerical Methods
EXAMPLE: What will be the value of y after the following code is executed? x = 3 if x > 1 and x < 2: y = 2 elif x > 2 and x < 4: y = 4 else: y = 0 print(y) ... Note that if you want the logical statement a < x < b, this is two conditional statements, a < x and x < b. In Python, you can type ...
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ else if python: understanding the nested conditional statements
Else if Python: Understanding the Nested Conditional Statements
October 14, 2024 - Now let's modify the example where none of the conditions evaluate to True: x = 3 if x < 2: print("x is less than 2") elif x > 5: print("x is greater than 5") else: print("x is between 2 and 5") In this case, both the conditions x < 2 and x ...
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ if-statement
Python If Statement: Master Conditional Logic | Learn Coding
def check_temperature(temp): if temp > 30: return "It's a hot day." elif temp > 20: return "It's a nice day." else: return "It's cold." print(check_temperature(25)) # "It's a nice day." In Python, some non-boolean values evaluate to True or False, too. Such "truthy" or "falsy" values can be ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_if_else.asp
Python Else Statement
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The else keyword catches anything which isn't caught by the preceding conditions. The else statement is executed when the if ...
๐ŸŒ
Tulane University Libraries
libguides.tulane.edu โ€บ condanditer โ€บ ifelse
IF...ELSE Statements - Intermediate Concepts in Python: Conditions and Iteration - Library Guides at Tulane University
May 13, 2025 - The following code demonstrates the first use of IN. Copy the following code on the left in your IDE to execute the process shown in the image on the right. list1 = [1,2,4,5] Jupyter Notebook View if 3 in list1: print ("3 is in list") else: print ("3 not in list")
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-else-if-statement-example
Python Else-If Statement Example
July 1, 2022 - Of course it is Python!") # ^ # IndentationError: expected an indented block after 'if' statement on line 3 ยท Writing if statements on their own, especially multiple of them, is not that helpful. It's also not considered best practice when the program grows larger and larger. This is why an if statement is usually accompanied by an else statement.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Input in if/else statements - Python Help - Discussions on Python.org
December 15, 2023 - I am a new programmer, I donโ€™t really know what I am doing that well, but I was sitting in class, and I thought to myself: hmm, can you put an input in an if-else statement?" and asked my professor, and he said that he hโ€ฆ
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ your ultimate python tutorial for beginners โ€บ python if-else statement: syntax and examples
If Else Statement in Python: Syntax and Examples Explained
April 16, 2025 - The if-else statement is used to execute both the true part and the false part of a given condition. If the condition is true, the if block code is executed.
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
ScholarHat
scholarhat.com โ€บ home
If Else Statement in Python Example
September 11, 2025 - It uses the syntax value_if_true if condition, else value_if_false. This statement checks the condition and returns one value if it is True and another if it is False. ... In this example, the ternary statement determines whether the age is ...