Computer Science, asked by deathprincess6365, 9 months ago

What gets printed with the following code ?
x = True
y = False
z = False
if not x or y :
print 1
elif not x or not y and z:
print 2
elif not x or y or not y and x:
print 3
else:
print 4

Answers

Answered by adarsh7457
1

Answer:

x= true hope it helps you.

Explanation:

byy

Answered by anindyaadhikari13
11

Given C∅de:

x = True

y = False

z = False

if not x or y :

print 1

elif not x or not y and z:

print 2

elif not x or y or not y and x:

print 3

else:

print 4

Corrected C∅de:

x = True

y = False

z = False

if not x or y :

print (1)

elif not x or not y and z:

print (2)

elif not x or y or not y and x:

print (3)

else:

print (4)

Output:

  • 3

Explanation:

It's given that,

  1. x = True
  2. y = False
  3. z = False

not x or y

= not True or False

= not True [True or False is true as one condition is true.]

= False [not True means False]

Therefore, the result is false.

>> If block will not execute.

Now, check the second condition,

not x or not y and z

= not True or not False and False

= False or True and False

Order of evaluation is from left to right.

= (False or True) and False

= True and False

= False [As one condition is False]

Therefore, the result is false.

>> First else-if block will not execute.

Now, check the next condition,

not x or y or not y and x

= not True or False or not False and True

= False or False or True and True [not True = False and not False = True]

= (False or False) or True and True

= (False or True) and True [False or False is False as whole condition is False]

= True and True [True as one condition is True]

= True

Therefore, result is True,

>> This block will execute.

∴ Output: 3

Similar questions