Turn on thread page Beta
    • Thread Starter
    Offline

    7
    ReputationRep:
    What sign do I use to divide two numbers in python and get the remainder of the two?
    Offline

    9
    ReputationRep:
    % (modulus) I think
    • Thread Starter
    Offline

    7
    ReputationRep:
    (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?
    Offline

    20
    ReputationRep:
    (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.
    Offline

    9
    ReputationRep:
    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
    Offline

    18
    ReputationRep:
    (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...

    /
    Offline

    15
    ReputationRep:
    (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
    Offline

    13
    ReputationRep:
    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.
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: October 21, 2017

University open days

  1. University of Bradford
    University-wide Postgraduate
    Wed, 25 Jul '18
  2. University of Buckingham
    Psychology Taster Tutorial Undergraduate
    Wed, 25 Jul '18
  3. Bournemouth University
    Clearing Campus Visit Undergraduate
    Wed, 1 Aug '18
Poll
How are you feeling in the run-up to Results Day 2018?

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

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.