🌐
GitHub
github.com › aisha-batool › Python-Practice-Exercises › blob › master › 5- IF, ELSE AND ELSE IF STATEMENTS, TESTING SET OF CONDITIONS.pdf
Python-Practice-Exercises/5- IF, ELSE AND ELSE IF STATEMENTS, TESTING SET OF CONDITIONS.pdf at master · aisha-batool/Python-Practice-Exercises
Basic Python Practice Exercises for brushing up Python Syntax - Python-Practice-Exercises/5- IF, ELSE AND ELSE IF STATEMENTS, TESTING SET OF CONDITIONS.pdf at master · aisha-batool/Python-Practice-Exercises
Author   aisha-batool
🌐
CS-IP-Learning-Hub
csiplearninghub.com › python-if-else-conditional-statement-practice
70+ Python if else Statement Important Practice Questions - CS-IP-Learning-Hub
October 28, 2025 - Ans. num=int(input("Enter any number between 1 to 7 : ")) if num==1: print("January") elif num==2: print("February") elif num==3: print("March") elif num==4: print("April") elif num==5: print("May") elif num==6: print("June") elif num==7: print("July") elif num==8: print("August") elif num==9: print("September") elif num==10: print("October") elif num==11: print("November") elif num==12: print("December") else: print("Please enter number between 1 to 12") Q6.
Discussions

(beginner) if/elif/else exercises
Look up the “fizz buzz” problem, that’s an excellent example of if/elif/else More on reddit.com
🌐 r/learnpython
19
50
November 27, 2021
[BEGINNER COURSE] (If statement exercise went wrong)

It's really hard to tell what is wrong with your code because it isn't formatted properly. Python uses white-space to define and separate individual code blocks and what you've shown us is just a few dozen individual lines of code with no discernible separation between them.

That said, there are a few things that stand out right away:

  1. Your input needs to be stored somewhere. The way your code is written, the second this line executes and you respond to it then "POOF" it is gone. Open your terminal then type "python3" to open an interactive terminal. Type "input("What is your gender: ") and see what happens. Now type "gender = input("What is your gender:") What's the difference? Now type "gender" and see what happens.

  2. ".lower" is a string method that isn't being called (strings are objects that have methods associated with them and methods are like functions that need to be called). Just like when you call your functions at the end of your program with "is_male()" and "gender_print()", ".lower" needs "()" to call this method" Again, in your terminal type "my_string = 'THIS IS MY STRING.'" Now type "my_string.lower" and "my_string.lower()" What's the difference?

  3. Learn about scope. There are things happening inside your functions that are independent of what is happening outside of your functions. Variables that are declared inside your function are not necessarily the same as variables that are declared outside of it. If you want to pass attributes of your global scope (like what you captured in your input), then try passing it to your function as input like so "def is_male(gender)" and now you can use this gender in your conditional statement.

  4. Again, more scope issues. Lack of indenting makes it unclear, but it would appear that the variable male is being declared inside your variable and thus its scope is limited to inside of that function. If you want to use that variable outside of that function you have to return it to the global scope (end your function with "return male") and store it in a variable in the global scope to use it (try assigning your new function call to a variable with 'male = is_male()' and using this new variable).

I'm sure there are other ways to do these things and other users may have their thoughts or disagree with my opinions, but this is where I would start. Again, I'd like to say that it's a little hard to understand what your code is trying to do when I can't read it as it should be written with the correct formatting so I'm doing a little guess-work. Also, as a beginner, the interactive terminal is your friend. Build your code step-by-step and examine it as you go. Break your code in to manageable pieces that you can test independently so you can better find bugs and understand what your code is doing. When you're sure that each of these manageable pieces work correctly then add them to your ".py" file to run as a complete script.

I hope this helps!

More on reddit.com
🌐 r/learnpython
17
0
December 30, 2021
Practice python coding
I can only higly recommend https://www.codingame.com/home You have puzzles that are easy to harder (and extra harder). And you have challenge (quick challenge, long challenge)... It's very fun. More on reddit.com
🌐 r/learnprogramming
72
638
February 27, 2019
if statement with multiple or conditions
If you enter "r", then let's reduce your conditions: if human != 'r' or human != 'p' or human != 's': if False or True or True if True That's why. You want to change your logic to something like if human not in ('r', 'p', 's'): More on reddit.com
🌐 r/learnpython
49
104
March 26, 2020
People also ask

Discuss how Python's 'elif' statement benefits program flow compared to multiple 'if' statements.
The 'elif' statement allows for multiple conditions to be evaluated sequentially and provides an optimized approach compared to using multiple independent 'if' statements. When using 'elif', if a condition is True, the associated code block executes and the rest of the conditions are skipped, thus improving efficiency. In contrast, multiple 'if' statements will evaluate every condition, regardless of whether one has already been satisfied, which can lead to unnecessary processing and potentially slower execution times. 'Elif' thus streamlines the decision-making process .
🌐
scribd.com
scribd.com › document › 787393726 › Python-if-Else-Statement-Important-Practice-Questions
Python If-Else Practice Questions | PDF | Computer Programming ...
What is the importance of using elif over a nested if within a single decision tree in Python?
Using 'elif' instead of a nested 'if' within a single decision tree is important for clarity and readability of the code. It places all conditional statements at the same indentation level, clearly reflecting the hierarchy of decision making. This reduces complexity and makes the logic easier to follow and debug. Nested 'if' statements can create deep indentation and complex branching, which may lead to errors and decrease maintainability. 'Elif' provides a straightforward way to handle multiple exclusive conditions, making it preferable in many cases .
🌐
scribd.com
scribd.com › document › 787393726 › Python-if-Else-Statement-Important-Practice-Questions
Python If-Else Practice Questions | PDF | Computer Programming ...
In what scenarios would a programmer prefer 'if-elif-else' structure rather than multiple independent 'if' statements?
A programmer would prefer the 'if-elif-else' structure over multiple independent 'if' statements in scenarios where conditions are mutually exclusive and should not evaluate once a preceding condition has been satisfied. This is crucial in decision trees to ensure only one code block executes, preventing unnecessary checks which could occur if multiple 'if' statements are used. For instance, assigning grades based on score ranges where only one grade should be given, ensuring cleaner, more efficient code execution .
🌐
scribd.com
scribd.com › document › 787393726 › Python-if-Else-Statement-Important-Practice-Questions
Python If-Else Practice Questions | PDF | Computer Programming ...
🌐
Scribd
scribd.com › document › 904129932 › Elif
Python if-elif-else Practice Questions | PDF
Question: Input a character and: ... consonant  Else print “Not an alphabet” · Question: Take two numbers and an operator (+, -, *, /) from the user....
🌐
edSlash
edslash.com › home › if else practice questions in python
if else practice questions in Python - edSlash
September 27, 2025 - Practice your Python skills with our list of if-else practice questions. Each question comes with a detailed solution to help you learn and improve.
🌐
Reddit
reddit.com › r/learnpython › (beginner) if/elif/else exercises
r/learnpython on Reddit: (beginner) if/elif/else exercises
November 27, 2021 -

Hi all.

Can you recommend if/elif/else exercises for beginner level?

I'm studying the "100 days of Python" by Angela Yu and, although I feel like I'm understanding some of the content, I feel like I should study this subject more before moving on with the lessons

Thanks in advance.

🌐
Scribd
scribd.com › document › 787393726 › Python-if-Else-Statement-Important-Practice-Questions
Python If-Else Practice Questions | PDF | Computer Programming | Software Engineering
Python if Else Statement Important Practice Questions - Free download as PDF File (.pdf), Text File (.txt) or read online for free. Ok
🌐
Scribd
scribd.com › document › 770943237 › python-if-else-exercises-pdf
Python If Else Exercises PDF | PDF
python-if-else-exercises-pdf - Free download as PDF File (.pdf), Text File (.txt) or read online for free.
Find elsewhere
🌐
TutorialAICSIP
tutorialaicsip.com › home › xi practicals › if-elif-else python exercises class11
if-elif-else python exercises Class11 - TutorialAICSIP
August 18, 2025 - print("/'sh/' for Short") print("/'p/' for Pants") print("/'t/' for t-shirts") opt = input("Enter the product code (/'sh/',/'p/',/'sht/')?:")) amt = int(input("Enter the amount:")) if opt=='s' opt=='S': if amt>0 and amt<100: dis = 0 elif amt>100 and amt<200: dis = amt * 0.05 elif amt>201 and amt<300: dis = amt * 0.1 else: dis = amt * 0.18 elif opt=='p' opt=='P': if amt>0 and amt<100: dis = amt * 0.03 elif amt>100 and amt<200: dis = amt * 0.08 elif amt>201 and amt<300: dis = amt * 0.12 else: dis = amt * 0.20 if opt=='t' opt=='T': if amt>0 and amt<100: dis = amt * 0.05 elif amt>100 and amt<200: dis = amt * 0.10 elif amt>201 and amt<300: dis = amt * 0.15 else: dis = amt * 0.22 bill_amt = amt - dis print("Customer has to pay:",bill_amt)
🌐
George Washington University
www2.seas.gwu.edu › ~simhaweb › cs1012 › unit1 › module1 › module1.html
Module 1: Conditionals
x = 5 y = 4 if x > y: print('Hey, x is bigger') else: print('Who said x is bigger?') print('In fact, y is bigger') print("OK, we're done") ... my_ifexample3.py and examine the output. Then, change the value of y to 6. What is the output? Change y to 5. What is the output?
🌐
Pythonista Planet
pythonistaplanet.com › examples-of-conditional-statements-in-python
17 Python if-else Exercises and Examples – Pythonista Planet
May 26, 2022 - p = 30 q = 20 if ((p<q) | (p==q)): print("Either p is less than q or p is equal to q") elif ((p==30) & (q==30)): print("p and q are equal") elif (p!=q): print("p is not equal to q") else: print("p is greater than q")
🌐
PYnative
pynative.com › home › python exercises › python loops exercises: 40+ coding problems with solutions
40 Python Loops Coding Exercises with Solutions – PYnative
June 13, 2026 - num = 5 factorial = 1 if num < 0: print("Factorial does not exist for negative numbers") elif num == 0: print("The factorial of 0 is 1") else: for i in range(1, num + 1): factorial = factorial * i print(f"The factorial of {num} is {factorial}")Code language: Python (python) Run
🌐
Nanyang Technological University
libguides.ntu.edu.sg › python › ifelifelse
1.13 Conditional statements (if-elif-else) - Python for Basic Data Analysis - LibGuides at Nanyang Technological University
3. If-elif-else - Assign 0 to z. If x is bigger than 0, print "x is a positive number". Else if x is zero, print "x is 0". Else, print "x is a negative number". ... Python If ...
🌐
Learn with Yasir
yasirbhutta.github.io › python › docs › if-elif-else › practice-and-progress › exercises-if-elif-else.html
Python if‑elif‑else Exercises – Practice Conditional Logic | Learn with Yasir
Practice Python if‑elif‑else statements with beginner-friendly exercises. Strengthen your understanding of conditional logic, syntax, and control flow with hands-on coding problems.
🌐
w3resource
w3resource.com › python-exercises › python-conditional-statements-and-loop-exercises.php
Python conditional statements and loops - Exercises, Practice, Solution - w3resource
Learn about Python conditional statements and loops with 44 exercises and solutions. Practice writing code to find numbers divisible by 7 and multiples of 5, convert temperatures between Celsius and Fahrenheit, guess numbers, construct patterns, count even and odd numbers, and much more.
🌐
Codesolid
codesolid.github.io › solutions › BooleanExpressionsExercises.html
Python If/Else and Booleans: Examples and Practice Questions — Python In Practice
water_level = 5 if water_level and water_level < 3: print("Normal operations") elif water_level >= 3 and water_level <= 4.5: print("Call City Manager") else: print("Open flood gates and call City Manager")
🌐
BrainStation®
brainstation.io › learn › python › if-statement
Python If Statement (2026 Tutorial & Examples) | BrainStation®
February 4, 2025 - Create a new notebook and name it python-control-flow-exercise. Follow the steps below to implement the exercise. By end, you will learn how to write conditional logic using if...elif...else statements.
🌐
365 Data Science
365datascience.com › blog › tutorials › python tutorials › python elif statement: exercises
Python ELIF Statement: Exercises – 365 Data Science
April 24, 2023 - If y is not greater than 5, the computer will think: “else if y is less than 5”, written “elif y is less than 5”, then I will print out “Less”. And the else-statement follows as a tail with the respective block that says “return ...
🌐
Medium
medium.com › 365datascience › python-elif-statement-exercise-621d7440cfac
Python ELIF Statement Exercise | by 365 Data Science | 365 Data Science | Medium
June 26, 2019 - if x>=y+z or y>= x+z or z>= x+y: print("The triangle does not exist") elif x==y and x==z: print ("Equilateral") elif x==y or x==z or y==z: print ("Isosceles") else: print("Obtuse")