In: Computer Science
Write Boolean expressions in Python Programming: A currently have a different value than B B less than the sum of the current values of A and C C is no more than 15. 75 is between the values of integers A and B Number N is divisible by 2 or it is divisible by 3. X is positive and Y is positive
Answer
In Python, variables are created the moment we assign a value to it. It also doesn't need a semicolon at the end of the statement. Python has some unique operators like and, or, not, is, etc. Based on this information, let's write the statements one-by-one.
1) A currently have a different value than B
Here, we can use both operators '!=' and ' is not'.
So, the answers are A != B and A is not B
2) B less than the sum of the current values of A and C
For this, the operator '< ' is used
So, the answer is B < A+C
3) C is no more than 15
The value of C is either less than 15 or equal to 15. The operator '<=' is used for this.
So, the answer is C <= 15
4) 75 is between the values of integers A and B Number
75 is between integers A and B. Let's assume B is greater than A here. Then, the above statement is equivalent to A is less than 75 and B is greater than 75.
So, the answer is A < 75 and B >75
5) N is divisible by 2 or it is divisible by 3
For testing divisibility, we check whether the remainder is zero or not. '%' operator is used to find the remainder in python.
So, the answer is N %2 == 0 or N %3 == 0
Note: we can also use 'is' operator instead of '=='.
6) X is positive and Y is positive
Means X is greater than zero and Y is also greater than zero
So, the answer is X > 0 and Y > 0