What if we want the quotient and remainder of a single division operation? | Sololearn: Learn to code for FREE!

+11

What if we want the quotient and remainder of a single division operation?

Can we write the program for quotient and remainder in a single line or do we have to write it separately?

8/25/2018 5:57:54 PM

Anushka Vaidya

15 Answers

New Answer

+38

There is a function just for you :) >>> q, r = divmod(10, 3) >>> q 3 >>> r 1

+8

Dale Edward it works! This might be more useful though https://code.sololearn.com/crphN61yl9h5/?ref=app

+7

I think print(10//3, 10%3) would work

+4

x = 10 y = 3 print("quotient =", x//y,"remainder =", x%y)

+3

x= int(input("enter number 1") y= int(input("enter number 2") print(x//y , x%y)

+2

Quotient print(x//y) Remainder print(x%y)

+1

Idk but once i find the answer i will come back and post it.

+1

x = 10 y = 3 print("quotient =", x//y,"remainder =", x%y)

+1

Eesa Adam thanks for the code, helps to illustrate!

+1

print( 10 % ( 18 // 5 ) )

0

Just make sure to seperate it by parenthesis

0

We can use both the function in one command eg. print(7%(5//2)) Ansr will be 1

0

I notice this in python for beginners in some exercise That would changes in 888 minutes into hours print(888//60) - 14 hours print(888%60) - 48 minutes

0

Sathyaseelan so whats your question exactly, you are totally correct in the quotient and remainder.

-1

There is a function just for you :) >>> q, r = divmod(10, 3) >>> q 3 >>> r 1