402,996 views
8 votes
8 votes
Give your own example of a nested conditional that can be modified to become a single conditional, and show the equivalent single conditional.

User Alexforrence
by
2.3k points

1 Answer

18 votes
18 votes

Answer:

following are the program to the given question:

Program:

x = 0#defining an integer variable that holds a value

if x < 0:#defining if that checks x less than 0

print("This number ", x, " is negative.")#print value with the message

else:#defining else block

if x > 0:#defining if that checks x value greater than 0

print(x, " is positive")#print value with message

else:#defining else block

print(x, " is 0")#print value with message

if x < 0:#defining another if that checks x less than 0

print("This number ", x, " is negative.")

elif (x > 0):#defining elif block that check x value greater than 0

print(x, " is positive")#print value with message

else:#defining else block

print(x, " is 0")#print value with message

Output:

Please find the attachment file.

Step-by-step explanation:

In this code, an x variable is defined which holds a value that is "0", in the next step nested conditional statement has used that checks the x variable value and uses the print method that compares the value and prints its value with the message.

In another conditional statement, it uses if that checks x value less than 0 and print value with the negative message.

In the elif block, it checks x value that is greater than 0 and prints the value with the positive message, and in the else block it will print the message that is 0.

Give your own example of a nested conditional that can be modified to become a single-example-1
User Walter Macambira
by
3.2k points