+ 22

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?

25th Aug 2018, 5:57 PM
Anushka Vaidya
Anushka Vaidya - avatar
16 Answers
+ 66
There is a function just for you :) >>> q, r = divmod(10, 3) >>> q 3 >>> r 1
25th Aug 2018, 7:37 PM
Just A Rather Ridiculously Long Username
+ 13
x = 10 y = 3 print("quotient =", x//y,"remainder =", x%y)
12th Jun 2021, 3:48 AM
Sheena Turcios
Sheena Turcios - avatar
+ 10
I think print(10//3, 10%3) would work
16th Apr 2021, 7:05 PM
Dale Edward
Dale Edward - avatar
+ 10
Dale Edward it works! This might be more useful though https://code.sololearn.com/crphN61yl9h5/?ref=app
22nd Apr 2021, 1:31 PM
Eesa Adam
Eesa Adam - avatar
+ 4
x= int(input("enter number 1") y= int(input("enter number 2") print(x//y , x%y)
28th Sep 2021, 4:31 PM
Rishav Kumar
Rishav Kumar - avatar
+ 1
Quotient print(x//y) Remainder print(x%y)
26th Mar 2021, 10:45 AM
Anubhav Kumar
+ 1
Idk but once i find the answer i will come back and post it.
12th Apr 2021, 10:35 AM
Reginald Gray
+ 1
x = 10 y = 3 print("quotient =", x//y,"remainder =", x%y)
29th Apr 2021, 9:50 AM
DHINAKARAN R
DHINAKARAN R - avatar
+ 1
Eesa Adam thanks for the code, helps to illustrate!
9th May 2021, 9:12 AM
Andeta Karamina
Andeta Karamina - avatar
0
Just make sure to seperate it by parenthesis
7th Jun 2021, 2:05 PM
Robert DuBose
Robert DuBose - avatar
0
print( 10 % ( 18 // 5 ) )
7th Jun 2021, 2:06 PM
Robert DuBose
Robert DuBose - avatar
0
We can use both the function in one command eg. print(7%(5//2)) Ansr will be 1
7th Jul 2021, 11:41 AM
fashion adda udaipur
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
10th Sep 2021, 3:36 PM
SATHYASEELAN P
SATHYASEELAN P - avatar
0
Sathyaseelan so whats your question exactly, you are totally correct in the quotient and remainder.
10th Sep 2021, 8:27 PM
Reginald Gray
0
use %
11th Apr 2022, 4:51 AM
Jena
- 1
There is a function just for you :) >>> q, r = divmod(10, 3) >>> q 3 >>> r 1
10th Jun 2021, 3:31 PM
Abdelrahman shaheen