Last day, we learned terminal basics, conditional statements, how to use Boolean datatype in Python, and what dynamic type is. Today, we will see some more things that I learned in Python.
I learned was Control Flow Statements.
Control Flow Statement
Control Flow Statements are used to control the execution flow of a program type of three.
1.Condition Statements
2.Lopping Statements
3.Jump Statements
Today we are going to learn two statements.😁
One is Conditional Statements, and another one is Looping Statements.
Condition Statements
Condition statement means checking a condition and running the code based on that condition.
Condition Statement key words
- if
- else
- elif 🤔
In JavaScript, I used else if.
In Python, we use elif for the same purpose. ( else + if = elif 😜 )
a =10
b =20
c =21
if a>=b and a>=c:
print(a)
elif b>=a and b>=c:
print(b)
elif c>=a and c>=b:
print (c)
OutPut:
c
- First I created three variables and assigned values to them.
- Then I used an if-elif condition statement to check which value is greater.
- Used to (ex) a>=b and a>=c, b>=a and b>=c, c>=a and c>=b
- Finally the program prints the largest number.📈
Looping Conditions
A looping condition is used to repeat a block of code again and again until the condition becomes false. two Type of Looping Conditions is Here
For Loop Condition and While Loop Conditions. but I Today only Learn in While Loop Condition.
While Loop
It is used to run the code until the condition becomes false.
I was create a while loop conditions by 4 task. see the task easy to Understand in while loop condition..
Task no: 1) 5 4 3 2 1
count =5
while count>=1:
print(count,end=" ")
count-=1
Output :
5 4 3 2 1
------------------------------
Task no: 2) 10 8 6 4 2
loop=10
while loop>= 2:
print(loop,end=" ")
loop-=2
Output :
10 8 6 4 2
------------------------------
Task no3) 15 12 9 6 3
count1 =15
while count1>=3:
print(count1,end=" ")
count1-=3
Output :
15 12 9 6 3
------------------------------
Task no:4) 25 20 15 10 5
count2 =25
while count2>=5:
print(count2,end=" ")
count2-=5
Output :
25 20 15 10 5
EX :
Task no 1
Full program flow:
- Create a Variable and Initialization starting value. count = 5
- Used a while Loop condition and Check the Condition. while count>=1:
- print the Count. print( Count )
- value decrease. count-=1 meaning count=5 > > 5 - 1 = 4 > > count =4
- again condition check. count value = 4 again print and again decrement the count.
- When the condition becomes false the loop stops. [ex] count is 0 >=1.
And I use All print inside end=" "
what is this end=""🤔
- end="" is used to control what comes after the print output.
- Normally print moves to the next line.😒
OutPut:
5
4
3
2
1
- But using end="" we can print output in the same line.😃
OutPut :
5 4 3 2 1
- We can use space, star, dash, or other symbols inside end="".😯
end="*",end="_"
OutPut :
5*4*3*2*1
5_4_3_2_1
I will continue my Python journey tomorrow...👋
Top comments (0)