In this python nested if else program, we will find out given input belongs to which group.
Steps to solve the program
- Take a number between 1-100 as input through the user.
- Create 10 groups of numbers between 1-10. Each group will have 10 numbers (i.e. 1-10,11-20,….,91-100) using nested if-else statements.
- With the help of nested if-else statements check the input number lies in which group.
- Print the respective output.
num = int(input("Enter a number: "))
if 1<= num <=10:
print("The given number belongs to 1st group")
elif 11<= num <=20:
print("The given number belongs to 2nd group")
elif 21<= num <=30:
print("The given number belongs to 3rd group")
elif 31<= num <=40:
print("The given number belongs to 4th group")
elif 41<= num <=50:
print("The given number belongs to 5th group")
elif 51<= num <=60:
print("The given number belongs to 6th group")
elif 61<= num <=70:
print("The given number belongs to 7th group")
elif 71<= num <=80:
print("The given number belongs to 8th group")
elif 81<= num <=90:
print("The given number belongs to 9th group")
elif 91<= num <=100:
print("The given number belongs to 10th group")
else:
print("Invalid number")
Output :
Enter a number: 36
The given number belongs to 4th group