We can structure our Python program in 3 ways-
All these 3 ways can be combined together to create a full program.
Sequential Steps
print("Demonestrate sequential steps in Python") # Step 1
num1 = 100 # Step 2
num2 = 900 # Step 3
sum = num1 + num2 # Step 4
print(f"Sum of {num1} and {num2} is: {sum}") # Step 5
my_input = input("Enter some value:") # Step 6
print("You have entered: ", my_input) # Step 7
print(f"Value of {num2} * {my_input} is: {num2 * int(my_input)}") # Step 8
PythonOutput:
Demonestrate sequential steps in Python
Sum of 100 and 900 is: 1000
Enter some value:12345
You have entered: 12345
Value of 900 * 12345 is: 11110500
PlaintextConditional Steps
my_val = 88
if my_val < 70:
print("Need improvement")
elif my_val < 90:
print("Good")
else: # More than 90
print("Excellent")
PythonOutput:
Good
PlaintextRepeated Steps
my_val = 5
print("Output of first loop:")
while my_val > 2:
print(my_val)
# Decrease the value of my_val
my_val = my_val - 1
print("Output of second loop:")
for i in range(0, 5):
print(i)
PythonOutput:
Output of first loop:
5
4
3
Output of second loop:
0
1
2
3
4
Plaintext