92,042 views
28 votes
28 votes
What is the output of this code?

num-7
if num > 3:
print("3")
if num < 5:
print("5")
if num --7:
print("7")

User Osnat
by
2.6k points

1 Answer

12 votes
12 votes

Answer:

The output is:

3

7

Step-by-step explanation:

Given

The code segment

Required

The output

The given code segment has 3 independent if statements; meaning that, each of the if conditions will be tested and executed accordingly

This line initializes num to 7

num=7

This checks if num is greater tha 3; If yes, "3" is printed

if num > 3:

print("3")

The above condition is true; so, "3" will be printed

This checks if num is less than 5; If yes, "5" is printed

if num < 5:

print("5")

The above condition is false; so, "5" will not be printed

This checks if num equals 5; If yes, "7" is printed

if num ==7:

print("7")

The above condition is true; so, "7" will be printed

So, the output is:

3

7

User Ncank
by
2.9k points