In-depth Look at Python Control Structures: Day 12

I'm Archana, pursuing Graduation in Information technology and Management. I'm a fresher with expertise in Python programming. I'm excited to apply my skills in AI/ML learning , Python, Java and web development. Looking forward to collaborating and learning from industry experts.
Introduction :
Welcome back to my Python journey! Yesterday, I laid the foundation with type casting in python. Today, I dove into control structures and functions, essential building blocks of any programming language. Let's explore what I learned!
Control Structure :
Contitional Control Structure
if
if elif
if elif else
Loop / Iterative Control Structure :
while
for
selection Control Statements :
break
continue
pass
if:
Syntax :
if condition : statement or
if condition :
statement-1
statement-2
statement-3
If condition is true then statements will be executed.
EXAMPLE :
#check a number is +ve
no =int (input ("Enter a number"))
if no > 0 : print ("+ve number")
or
no =int (input ("Enter a number"))
if no > 0 :
print ("+ve number")

if-else:
Syntax :
if condition :
Action-1
else :
Action-2
if condition is true then Action-1 will be executed otherwise Action-2 will be executed.
example:
#check a number is +ve or -ve
no =int (input ("Enter a number"))
if no > 0 :
print ("+ve number")
else :
print ("-ve number")

if-elif-else:
Syntax:
if condition1:
Action-1
elif condition2:
Action-2
elif condition3:
Action-3
elif condition4:
Action-4
else:
Default Action
Based condition the corresponding action will be executed
Example 1:
#check a number is +ve or -ve or zero
no =int (input ("Enter a number"))
if no > 0 :
print ("+ve number")
elif no < 0 :
print ("-ve number")
else:
print ("equal to zero")

Example 2:
#Check a number is even or odd.
no = int ( input ( 'Enter a number : '))
if no % 2 == 0 :
print ( 'hi hi !')
print ( 'i am even !')
else :
print ( 'i am odd !' )
print ( 'bye bye Program !')

Example 3:
#Greate between three number.
no1 = int ( input ( ' Enter no1 :' ))
no2 = int ( input ( ' Enter no2 :' ))
no3 = int ( input ( ' Enter no3 :' ))
if no1 > no2 :
if no1 > no3 :
max = no1
else :
max = no3
else:
if no2 > no3 :
max = no2
else:
max = no3
print (max, "is max number")

Example 4:
minTime = 8
maxTime = 16
workingTime = int ( input ( 'Enter your working time : '))
if minTime <= workingTime <= maxTime :
if workingTime == 8 :
payment = 200
elif workingTime > 8 and workingTime < 13 :
payment = 200 + ( workingTime - 8 ) \50*
else :
payment = 200 + 200 + ( workingTime - 12 ) *100
print ( 'your payment is : ‘ payment )
else :
print ( 'INVALID TIME ENTERED !')
pin = int (input ("Enter your ATM pin "))
amount = 0.0
if pin == 123:
while (True ) :
C = input ( "D for Deposite\nW for withdraw\nS for mini statements\nE for exit ")
if C == "D":
Damount = float (input ("Entetr Deposite amount"))
amount += Damount
print ("your current balance =", amount)
elif C == "W" :
Wamount = float (input ("Enter withdraw amount"))
if Wamount < amount :
amount -= Wamount
print ("your current balance =", amount)
else :
print ("Sorry")
elif C == "S":
print ("your current balance =", amount)
elif C == "E" :
print ("Thank you, visit again.... ")
exit(0)
else :
print ("invalid pin number")
exit (0)

Challenges :
Understanding loop iteration.
Handling errors.
Resources :
Official Python Documentation: Control Structures
W3Schools' Python Tutorial: Control structures
Scaler's Python Course: Control Flow
Goals for Tomorrow :
Explore something more about control structure.
Learn about control statements.
Conclusion :
Day 12’s a success!
What are your favorite Python resources? Share in the comments below.
Connect with me :
GitHub: [ https://github.com/p-archana1 ]
LinkedIn : [ https://www.linkedin.com/in/archana-prusty-4aa0b827a/ ]
Join the conversation :
Share your own learning experiences or ask questions in the comments.
HAPPY LEARNING!!
THANK YOU!!





