Python Code Example: Quotient and remainder

Code Example

dividend = int(input("Please enter dividend: "))
divisor = int(input("Please enter divisor: "))

quotient = dividend / divisor
remainder = dividend % divisor

print("Quotient is: " + repr(quotient))
print("Remainder is: " + repr(remainder))


Please enter dividend: 118
Please enter divisor: 12
Quotient is: 9.833333333333334
Remainder is: 10

Code Explanation

The code starts by asking the user to input two integers, the dividend and the divisor. These values are then stored in the variables dividend and divisor respectively.

Next, the code performs integer division and calculates the quotient and remainder. The quotient is calculated by dividing dividend by divisor and the result is stored in the quotient variable. The remainder is calculated by using the modulo operator (%) which gives the remainder of the division of dividend by divisor and the result is stored in the remainder variable.

Finally, the code prints the quotient and remainder values using the print function. The repr function is used to convert the quotient and remainder to a string representation, so that it can be concatenated with the string literal in the print statement.

This code performs basic arithmetic operations and demonstrates how to store values in variables, perform arithmetic operations, and print the results.