MWLS.com

Quotients and Remainders


Home | Articles | Mathematics | Quotients and Remainders Log in | Sign up

Dividing one number (the dividend) by another number (the divisor) to give a whole number (the quotient) and a remainder is fairly straightforward. However, it is easy to make a mistake, so I wrote a Python script to help me avoid errors…

. . .

import math
run = 1

print("n>>>>>>> Quotients and Remainders <<<<<<<n")

while(run == 1):
  strDividend = input("Enter a number (dividend): ")
  strDivisor = input("Enter a divisor: ")
  dividend = int(strDividend)
  divisor = int(strDivisor)
  quotient = math.trunc(dividend/divisor)
  print()
  print("Quotient = " + str(quotient))
  remainder = dividend - (quotient * divisor)
  print("Remainder = " + str(remainder))
  print()

run = int(input("1. Continue\n2. Quit \n\n"))
print()

if run == 2:
  exit()

. . .

This script is designed for working in a console environment.

I have, for a long time, wanted to run Python scripts on my websites. This is because I prefer to write programs in Python. This meant I had to rewrite my Python scripts in Javascript — the only client-side programming language that browsers support.

I’ve tried using Flask and other similar solutions, but I haven’t been able to get on with them.

I was about to give up on running Python on my websites when I came across Run Python Code on Websites: Exploring Brython by Kaustubh Gupta. I found his program for getting song lyrics particularly helpful for understanding Brython.

See Quotients and Remainders to see how I managed to get a version of the above script running on my website. You can use your browser to show the source of the page. This will show you how it works.

214   128

Become a member or supporter to get early access to new articles.




Support the Learning Pages project | ☕️ Buy me a coffee