Page 241 - Ai_V1.0_Class9
P. 241
Let us take an example of making a mango smoothie. The steps will be:
1. Put mango pieces in a Mixer jar
2. Add sugar
3. Add milk
4. Churn the mixer jar
5. Pour in a glass
Let us do some more examples:
Program 1: Input the first name and last name from the user and display the full name.
Algorithm
Flowchart
Step 1 Start
START
Step 2 Input FirstName, LastName
Step 3 FullName= FirstName + LastName
INPUT
Step 4 Display FullName First Name, Last Name
Step 5 Stop
Source Code: FullName=First Name+Last Name
FirstName=input("Enter your First Name: ")
LastName=input("Enter your Last Name: ")
Display
FullName=FirstName+" "+LastName Full Name
print("Hello! "+FullName+" Welcome to the World of
Python")
Output: STOP
Enter your First Name: Megha
Enter your Last Name: Sharma
Hello! Megha Sharma Welcome to the World of Python
Selection Statements
In Python,
• Selection flow of control is achieved through conditional statements.
• In the conditional/selection statements, flow of control is changed based on a condition. We specify the
condition in the program, which evaluates to either 'True' or 'False'.
• If condition is 'True' then the block of statement written for 'True' will be executed, and if the condition is 'False'
then the block of statements for 'False' will be executed.
• Conditional statements are also called branching statements because a program decides which statement to
execute based on the result of the evaluated condition.
• A block is identified by using an indentation (minimum 1 space). Ensure that all statements in one block are
indented at the same level.
• Python mainly provides three types of conditional statements—if, if…else and if…elif…else statements.
Let us learn about them in detail.
Introduction to Python 239

