Page 58 - Touhpad Ai
P. 58
floor_division = num1 // num2
# Display the results
print(num1, "+", num2, "=", addition)
print(num1, "-", num2, "=", subtraction)
print(num1, "*", num2, "=", multiplication)
print(num1, "/", num2, "=", division)
print(num1, "%", num2, "=", modulus)
print(num1, "**", num2, "=", exponentiation)
print(num1, "//", num2, "=", floor_division)
Output:
Enter the first number: 16
Enter the second number: 3
16 + 3 = 19
16 - 3 = 13
16 * 3 = 48
16 / 3 = 5.333333333333333
16 % 3 = 1
16 ** 3 = 4096
16 // 3 = 5
Comparison Operators
Comparison operators are used to compare two values and return a boolean result (True or False). They return True if the
comparison is true, otherwise return False. They are commonly used in conditional statements and loops.
Operator Description
== Checks if two operands are equal
!= Checks if two operands are not equal
> Checks if left operand is greater than right operand
< Checks if left operand is less than right operand
>= Checks if left operand is greater than or equal to right operand
<= Checks if left operand is less than or equal to right operand
Program 6: To demonstrate the use of comparison operators
# Uses of Comparison Operators
# Equal to
print("Equal to:", 10 == 5)
# Not equal to
print("Not equal to:", 10 != 5)
# Greater than
print("Greater than:", 10 > 5)
# Less than
print("Less than:", 10 < 5)
56 Touchpad Artificial Intelligence - XI

