Samples - October.Students - Week.2.HW 2
Samples - October.Students - Week.2.HW 2
OPERATORS
PROGRAM RegularDevision:
num2 = 5
num3 = num1 / num2
PRINT normal division of num1 by num2 = num3
END.
PROGRAM FloorDivision:
num1 = 12 num2 = 5
num3 = num1 // num2
PRINT floor division of num1 by num2 = num3
END.
# Output: floor division of 12 by 5 = 2
num1 = 12 num2 = 5
num3 = num1 // num2
print("floor division of", num1, "by", num2, "=", num3)
# Output: floor division of 12 by 5 = 2
This shows you that the // operator rounds down the result of the division of two numbers to the nearest whole number.
Even if the decimal point is 9, the // operator would still round the result down to the nearest whole number.
PROGRAM RoundNumber:
num1 = 29
num2 = 10
num3 = num1 / num2
num4 = num1 // num2
PRINT normal division of num1 by num2 = num3)
PRINT but floor division of num1 by num2 = num4)
END.
• print(x % y)
• Output: 1
Q.1: four operands output
END. END.
b =4
# Addition of numbers
add = a + b
# Subtraction of numbers
sub = a - b
# Multiplication of number
mul = a * b
Q.2: Sum of digits -- HW
• Given a three digit number. Find sum of numbers.
• Sample number: 179
• Output: 17