0% found this document useful (0 votes)
2 views11 pages

Selection Statements

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)
2 views11 pages

Selection Statements

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
You are on page 1/ 11

SELECTION STATEMENTS

A conditional statement is a feature in programming that allows the execution


of specific blocks of code based on whether a condition (or set of conditions) is
true or false. These statements enable decision-making in programs, allowing
the program to choose different paths of execution depending on the given
conditions.

Key Components of Conditional Statements:

1. Condition:
o A logical expression that evaluates to either true or false.
o Example: age >= 18 (checks if a person is 18 or older).

2. Action:
o The code that will be executed if the condition is true or false.

Example 1: Driving Eligibility

You need to create a algorithm that checks if a person is allowed to drive. If


they are 18 years or older, they can drive. If they are younger than 18, they
cannot.

Condition:

 age >= 18 (Checks if the person's age is 18 or older).

Example 2: Checking Bank Balance

You go to an ATM to withdraw money. The ATM will first check if you have
enough balance to withdraw. If you don't, it will show an error message.

Problem:

The ATM needs to decide whether to allow you to withdraw based on your
balance.

Condition:

 balance >= withdraw_amount (Checks if the bank balance is enough for


the withdrawal).
Example 3: Grading System

In schools, students receive grades based on their scores. For example:

 A score of 90 or more gives an A.


 A score between 80 and 89 gives a B.
 Any score below 80 gives a C.

Problem:

You want to assign a grade to a student based on their score.

Conditions:

1. score >= 90 (Checks if the score is 90 or more).


2. score >= 80 (Checks if the score is between 80 and 89).
3. Otherwise, the score is below 80.

Example 4: Online Shopping Discounts

1.Even or Odd Checker

2.Flow Chart to Calculate Grade of a Student


3.Check eligibility for vote

1. Leap Year Checker


Steps in the Flowchart:

1. Start: The program starts.


2. Read year: The user is prompted to input a year.
3. Is the year evenly divisible by 4?:
o If No (False): The year is not a leap year (since a leap year must be divisible by 4).
o If Yes (True): Move to the next condition.

4. Is the year evenly divisible by 100?:


o If No (False): The year is a leap year (any year divisible by 4 but not by 100 is a leap
year).
o If Yes (True): Move to the next condition.

5. Is the year evenly divisible by 400?:


o If No (False): The year is not a leap year (if divisible by 100 but not by 400, it's not a
leap year).
o If Yes (True): The year is a leap year (any year divisible by 400 is a leap year).

6. End: The process ends after determining whether the input year is a leap year or not.

Leap Year Rules:

 A year is a leap year if:


o It is divisible by 4, and
o It is not divisible by 100, unless it is divisible by 400.
7.Flow chart for findout biggest among three numbers
8.Flowchart for calculating grade
9.Perform mathematical operations
10.Flowchart for to a message based on time

11.
12.Raptor Flow chart to Find Square of an Integer

1. Raptor Flowchart for floor Function

You might also like