If x = 2 y = 5 z = 0 then find values of the following expressions: a. x == 2 b. x != 5 c. x != 5 && y >= 5 d. z != 0 || x == 2 e. !(y < 10)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


If x = 2 y = 5 z = 0 then find values of the following expressions: a. x == 2 b. x != 5 c. x != 5 && y >= 5 d. z != 0 || x == 2 e. !(y < 10)



If


x = 2
y = 5
z = 0



then find values of the following expressions:


x == 2
x != 5
x != 5 && y >= 5
z != 0 || x == 2
!(y < 10)



So this what I did code in Java. I want to code this in Python now. This has to work with boolean. But I'm stuck at the implementation in Python.





Where is the code?
– Geshode
7 mins ago





Python uses and, or, and not instead of &&, ||, and !. With those substitutions, those expressions become valid python.
– Patrick Haugh
5 mins ago


and


or


not


&&


||


!





This question might be liable to downvotes since it might not be useful.
– Mulliganaceous
3 mins ago




3 Answers
3



There are several differences between Java and Python.



One of which is the use of 'if' statements.



In python, an 'if' statement follows this structure:



if CONDITION:



elif CONDITION:



else:



The operators are also slightly different.



Rather than || it's or



Rather than & it's and



Boolean works similarly, except python capitalizes the first letter. True False



Hope this helps!



This is the answer.


x = 2
y = 5
z = 0

print(x == 2)
print(x != 5)
print(x != 5 and y >= 5)
print(z != 0 or x == 2)
print(not (y < 10))



which yields


True
True
True
True
False



Python uses words for symbolic operators, not operator symbols. For your Python
code, transform all these symbols into the cooresponding words - this is straightforward.


||


or


&&


and


!


not






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived