In: Computer Science
python
Show an example of three sequential and independent if blocks (make up your own) and Show an example of a nested if block (make up one of your own).
An example of three sequential and independent if blocks is given below:
#get user input
x = int(input("Enter a number \nx = "))
#check if the value of x is greater than 10
if x > 10:
print("x is greater than 10")
#check if the value of x is greater than 100
if x > 100:
print("x is greater than 100")
#check if the value of x is less than 100
if x < 100:
print("x is less than 100")
The screenshot of the above source code is given below:
OUTPUT:
Enter a number
x = 50
x is greater than 10
x is less than 100
An example of a nested if block is given below:
#get user input
x = int(input("Enter a number \nx = "))
#check if the value of x is greater than 10
if x > 10:
#check if the value of x is greater than 100
if x > 100:
print("x is greater than 100")
The screenshot of the above source code is given below:
OUTPUT:
Enter a number
x = 150
x is greater than 100