Find the division remainder of a number

前端 未结 12 1244
刺人心
刺人心 2020-11-28 07:30

How could I go about finding the division remainder of a number in Python?

For example:
If the number is 26 and divided number is 7, then the division remainder

12条回答
  •  臣服心动
    2020-11-28 08:32

    If you want the remainder of your division problem, just use the actual remainder rules, just like in mathematics. Granted this won't give you a decimal output.

    valone = 8
    valtwo = 3
    x = valone / valtwo
    r = valone - (valtwo * x)
    print "Answer: %s with a remainder of %s" % (x, r)
    

    If you want to make this in a calculator format, just substitute valone = 8 with valone = int(input("Value One")). Do the same with valtwo = 3, but different vairables obviously.

提交回复
热议问题