0% found this document useful (0 votes)
13 views3 pages

Conditional Statements in Programming

The document outlines various conditional statements in programming, including basic if statements, if-else statements, if-elif-else statements, and nested if statements. It provides tasks and examples for each type of statement, demonstrating how to evaluate conditions such as comparisons, string checks, and age classifications. Additionally, it includes more complex conditional structures that involve multiple conditions and nested checks for various scenarios.

Uploaded by

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

Conditional Statements in Programming

The document outlines various conditional statements in programming, including basic if statements, if-else statements, if-elif-else statements, and nested if statements. It provides tasks and examples for each type of statement, demonstrating how to evaluate conditions such as comparisons, string checks, and age classifications. Additionally, it includes more complex conditional structures that involve multiple conditions and nested checks for various scenarios.

Uploaded by

dark devil013
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Conditional Statement

Basic if Statements

1. Simple Comparison:
o Task: Write a program to check if a number x = 10 is greater than 5 and print
"x is greater than 5" if true.
o Example: if x > 5: print("x is greater than 5")
2. Check Even or Odd:
o Task: Given a number num = 8, write a program to print "Even" if num is
even.
o Example: if num % 2 == 0: print("Even")
3. String Check:
o Task: Check if the string text = "hello" starts with the letter "h" and print
"Starts with h" if true.
o Example: if [Link]("h"): print("Starts with h")
4. Greater Than Zero:
o Task: Write a program that prints "Positive" if the number number = 3 is
greater than zero.
o Example: if number > 0: print("Positive")
5. Check for Specific Value:
o Task: Check if fruit = "apple" is equal to "orange" and print "Not an
orange" if it is not.
o Example: if fruit != "orange": print("Not an orange")

if-else Statements

6. Check Adult or Minor:


o Task: Write a program to check if the age age = 20 is greater than or equal to
18 and print "Adult" if true, otherwise print "Minor".
o Example: if age >= 18: print("Adult") else: print("Minor")
7. Temperature Check:
o Task: Given temperature = 30, print "Hot" if the temperature is above 25,
otherwise print "Cool".
o Example: if temperature > 25: print("Hot") else: print("Cool")
8. Positive or Negative:
o Task: Write a program to check if number = -7 is positive or negative. Print
"Negative" if it is less than zero; otherwise, print "Positive".
o Example: if number < 0: print("Negative") else:
print("Positive")
9. String Length:
o Task: Given the string text = "Python", print "Short" if the length is less
than 5 characters, otherwise print "Long".
o Example: if len(text) < 5: print("Short") else: print("Long")
10. Grade Evaluation:
o Task: Check if a student’s score score = 85 is above or below 50 and print
"Pass" if the score is greater than or equal to 50; otherwise, print "Fail".
o Example: if score >= 50: print("Pass") else: print("Fail")

if-elif-else Statements

11. Temperature Range:


o Task: Write a program to categorize the temperature temp = 15 into "Cold",
"Warm", or "Hot". Print "Cold" for temperatures below 10, "Warm" for
temperatures between 10 and 25, and "Hot" for temperatures above 25.
12. Day of the Week:
o Task: Given day = 3, print the name of the day in the week, e.g., "Monday",
"Tuesday", etc. (1 for Monday, 2 for Tuesday, etc.).
13. Number Classification:
o Task: Classify the number num = -5 as "Negative", "Zero", or
"Positive".
14. Discount Eligibility:
o Task: Determine if a customer with purchase_amount = 150 is eligible for a
discount. Print "10% discount" if the amount is over 100, "5% discount" if
over 50, and "No discount" otherwise.
15. Age Group:
o Task: Given an age age = 16, print the age group: "Child" (0-12),
"Teenager" (13-19), "Adult" (20-64), or "Senior" (65 and over).

Nested if Statements

16. Nested Age Check:


o Task: Given age = 25, check if the person is a "Young Adult" (18-30) or
"Adult" (31 and over). Print "Young Adult" if true, otherwise "Adult".
17. Complex Temperature Check:
o Task: Given temperature = 22, determine if it’s "Cold" (below 10), "Cool"
(10-20), or "Warm" (21 and above). Print the corresponding category.
18. Nested Grading System:
o Task: Given score = 82, determine the grade: "A" (90-100), "B" (80-89),
"C" (70-79), or "F" (below 70).
19. Discount and Membership Check:
o Task: Given purchase_amount = 120 and is_member = True, determine if
the discount is "15% discount" for members with purchases over 100, "10%
discount" for members with purchases between 50 and 100, or "No
discount" for non-members.
20. Even Odd and Positive Negative Check:
o Task: Given num = -4, print "Positive Even", "Positive Odd",
"Negative Even", or "Negative Odd".

More Complex Conditional Structures

21. Check Multiple Conditions:


o Task: Given age = 45 and income = 60000, print "Middle-aged High
Income" if age is between 40 and 60 and income is above 50000; otherwise,
print "Other".

More Complex Conditional Structures

21. Check Multiple Conditions (Continued):


o Task: Given age = 45 and income = 60000, print "Middle-aged High
Income" if the age is between 40 and 60 and the income is above 50000;
otherwise, print "Other".
22. Nested Grade and Age Check:
o Task: Given score = 85 and age = 17, print "Teenager with A Grade" if
the score is between 85 and 100 and the age is between 13 and 19; otherwise,
print "Other".
23. Discount Based on Amount and Membership:
o Task: Given purchase_amount = 80 and is_member = False, print "10%
discount" if the amount is over 75; otherwise, print "No discount". If the
user is a member and the amount is over 50, print "15% discount".
24. Nested Condition with Range Check:
o Task: Given value = 75, check if the value is between 50 and 100. Print
"Within range" if true, otherwise check if it's less than 50 and print "Below
range", otherwise print "Above range".
25. Categorize Age into Groups:
o Task: Given age = 70, categorize into "Child" (0-12), "Teenager" (13-19),
"Adult" (20-64), or "Senior" (65 and over). Print the appropriate category.
o Discount".

You might also like