Conditional Statement Practice Question - I ( DS150423 )

What is the output of the following code :

x = 10
y = 50
if x ** 2 > 100 and y < 100:
    print(x, y)
1 Like

x = 10
y = 50
if x ** 2 > 100 and y < 100:
print(x, y)
output: code=0
#the condition in the if statement is not True, so the print statement will not execute.
The condition in the if statement is checking whether the square of x (which is 100) is greater than 100, which is not true, and whether y is less than 100, which is also not true. Since both conditions are false, the code inside the if statement will not execute.

So we can modify with the values of x and y.
For Eg:
x = 11
y = 99
if x ** 2 > 100 and y < 100:
print(x, y)

Output: 11 99

2 Likes

I think print would not be executed hence code will finish with no output on console. Not much familiar with python

1 Like

There is no output

Proof:
Because x* * 2 is 10* * 2 which is 100.
And if we look at the if statement x* * 2>100 will be seen by python as 100>100, And mathematically it is incorrect as there is a difference between greater than(>) and greater than equal to(>=). so x* * 2 will return false, and y<100 will return true

now there is a logical operator in btw i.e. ‘and’ so ‘False “and” True’ will give us False as a output and this output will be taken by our ‘if’ statement, and since ‘if’ statement received False it will not execute whatever is in it, Hence the output is nothing

HENCE PROVED :laughing: :laughing:

1 Like

Maam, code you provided has a syntax error.
if statement requires an indented block of code to execute if the condition is true.
Since the condition x ** 2 > 100 and y < 100 is not met since x ** 2 is 100, which is not greater than 100, the print statement would not be executed even if the code was fixed.

Here’s a corrected version of the code that will print the values of x and y if x ** 2 is greater than 90 and y is less than 100:

1 Like

x = 10
y = 50
if x ** 2 > 100 and y < 100:
print(x, y)
output: the program is not executed
Because,the condition in the if statement is not True, so the print statement will not execute.

1 Like

There is no output.

As for condition to be false we have not printed anything.
It will print only if condition is true otherwise it will not show anything.

1 Like

In if statement x**2 > 100 and y < 100
= 100>100 for x which is false and for y<100 i.e 50<100 is true.

when and is used both the conditions must be true,
Therefore the program will be executed but there will be no output.

1 Like