Computer Science, asked by sonali1512, 6 months ago

Cachudie between
and == . ( Give two points.) Back.
12
Write a single statement to add up the first digit and the last digit of a three digit number stored in the
variable named x and assign the sum to y.
[2]​

Answers

Answered by kishor9321
1

Answer:

The modulus operator

The modulus operator works on integers (and integer expressions) and yields the remainder when the first operand is divided by the second. In Python, the modulus operator is a percent sign (%). The syntax is the same as for other operators:

>>> quotient = 7 / 3 >>> print quotient 2 >>> remainder = 7 % 3 >>> print remainder 1

So 7 divided by 3 is 2 with 1 left over.

The modulus operator turns out to be surprisingly useful. For example, you can check whether one number is divisible by another—if x % y is zero, then x is divisible by y.

Also, you can extract the right-most digit or digits from a number. For example, x % 10 yields the right-most digit of x (in base 10). Similarly x % 100 yields the last two digits.

4.2. Boolean values and expressions

The Python type for storing true and false values is called bool, named after the British mathematician, George Boole. George Boole created Boolean algebra, which is the basis of all modern computer arithmetic.

There are only two boolean values: True and False. Capitalization is important, since true and false are not boolean values.

>>> type(True) <type 'bool'> >>> type(true) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'true' is not defined

A boolean expression is an expression that evaluates to a boolean value. The operator == compares two values and produces a boolean value:

>>> 5 == 5 True >>> 5 == 6 False

In the first statement, the two operands are equal, so the expression evaluates to True; in the second statement, 5 is not equal to 6, so we get False.

The == operator is one of the comparison operators; the others are:

x != y # x is not equal to y x > y # x is greater than y x < y # x is less than y x >= y # x is greater than or equal to y x <= y # x is less than or equal to y

Although these operations are probably familiar to you, the Python symbols are different from the mathematical symbols. A common error is to use a single equal sign (=) instead of a double equal sign (==). Remember that = is an assignment operator and == is a comparison operator. Also, there is no such thing as =< or =>.

4.3. Logical operators

There are three logical operators: and, or, and not. The semantics (meaning) of these operators is similar to their meaning in English. For example, x > 0 and x < 10 is true only if x is greater than 0 and less than 10.

n % 2 == 0 or n % 3 == 0 is true if either of the conditions is true, that is, if the number is divisible by 2 or 3.

Finally, the not operator negates a boolean expression, so not(x > y) is true if (x > y) is false, that is, if x is less than or equal to y.

Explanation:

HOPE MY ANSWERS HELPS U IF U HAD PLZZZ BRAINLIST ME AND FOLLOW ME

Answered by anonymouslygreat
0

Answer:

In Python:

y = int(str(x)[0]) + int(str(x)[2])

If it helped, please mark as brainliest. Have a nice day!

Similar questions