0% found this document useful (0 votes)
4 views2 pages

Python if Condition Questions

The document contains 50 Python if condition questions along with their solutions. It covers various scenarios such as checking if a number is positive, zero, negative, even, odd, and other string and list conditions. Each example provides a simple code snippet demonstrating the condition being checked.

Uploaded by

AARUNI RAI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python if Condition Questions

The document contains 50 Python if condition questions along with their solutions. It covers various scenarios such as checking if a number is positive, zero, negative, even, odd, and other string and list conditions. Each example provides a simple code snippet demonstrating the condition being checked.

Uploaded by

AARUNI RAI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

50 Python If Condition Questions with Solutions

1. Check if a number is positive


num = 5
if num > 0:
print("Positive number")

2. Check if number is zero


num = 0
if num == 0:
print("Zero")

3. Check if number is negative


num = -4
if num < 0:
print("Negative number")

4. Check if a number is even


num = 8
if num % 2 == 0:
print("Even")

5. Check if a number is odd


num = 9
if num % 2 != 0:
print("Odd")

6. Check if user is adult


age = 18
if age >= 18:
print("Adult")

7. Check if string is empty


s = ""
if s == "":
print("Empty string")

8. Check if string starts with 'A'


s = "Apple"
if s.startswith("A"):
print("Starts with A")

9. Check if list has more than 5 elements


lst = [1, 2, 3, 4, 5, 6]
50 Python If Condition Questions with Solutions

if len(lst) > 5:
print("List has more than 5 items")

10. Check if variable exists in list


x = 3
lst = [1, 2, 3]
if x in lst:
print("Exists")

You might also like