32
loading...
This website collects cookies to deliver better user experience
Types of Control structures.
if condition:
if-block
age= input('Enter your age:')
if int(age) >= 40:
print("You are an adult")
Enter your age:46
You are an adult
if condition:
if-block;
else:
else-block;
age = input('Enter your age:')
if int(age) >= 40:
print("You are an adult.")
else:
print("You are a child.")
Enter your age:30
You are a child.
if if-condition:
if-block
elif elif-condition1:
elif-block1
elif elif-condition2:
elif-block2
...
else:
else-block
age = input('Enter your age:')
your_age = int(age)
if your_age >= 70:
print("Your are old")
elif your_age >= 40:
print("Your young")
else:
print("null")
Enter your age:80
Your are old
for index in range(n):
statement
# list
numbers = [10,12,13,14,17]
# variable to store the sum
sum = 0
# iterate over the list
for index in numbers:
sum = sum+index
print("The sum is", sum)
The sum is 66
for index in range(4):
print(index)
0
1
2
3
while condition:
body
max = 6
counter = 0
while counter < max:
print(counter)
counter += 1
0
1
2
3
4
5