You are Here: Home

# divide by a number and get remainder watch

1. What sign do I use to divide two numbers in python and get the remainder of the two?
2. % (modulus) I think
3. (Original post by Ethan9133)
% (modulus) I think
yea thanks, do you know if there is a way to get the answer to the division at the same time and not just the remainder?
4. (Original post by Biology123ABC)
yea thanks, do you know if there is a way to get the answer to the division at the same time and not just the remainder?
In Visual Basic you can use the backslash (\) to do integer division (dividing the numbers but ignoring the remainder). For Python I think you have to do int(a/b) (the int bit can be used to convert anything to an integer) - I don't know of a shortcut like VB has.
5. Do you only need to print the results to the console or are you storing the divisions in variables to use in later calculations?
Python uses / for dividing i.e. print(6/2) prints 3
% outputs the remainder i.e. print(7%2) prints 1
you can also use variables in place of the numbers
you can also store the answer to the calculation in a variable too
6. (Original post by Biology123ABC)
yea thanks, do you know if there is a way to get the answer to the division at the same time and not just the remainder?
Come on dude...

/
7. (Original post by Biology123ABC)
yea thanks, do you know if there is a way to get the answer to the division at the same time and not just the remainder?
no way i know but // returns the maximum number of times the thing can be divided

so 1//3 gives 0 for example
(Original post by Speckle)
Come on dude...

/
wat that's just good ol regular divide % gives the remainder after diving as many times as possible
8. If you're looking to output the remainder and the division then you would have to write two separate lines of code to print out the two answers. One for using '/' and the other using '%'. I don't know if there is an operation that prints both together.

### Related university courses

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: October 21, 2017
Today on TSR

### He broke up with me because of long distance

Now I'm moving to his city

### University open days

Wed, 25 Jul '18
2. University of Buckingham
Wed, 25 Jul '18
3. Bournemouth University
Wed, 1 Aug '18
Poll
Useful resources

Can you help? Study Help unanswered threadsStudy Help rules and posting guidelines

## Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE