Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

asrowley

  • 3 years ago

Hi. I'm trying to compare e.g. 25/6 to 25%6 (modular arithmetic?) for the prime problem (2nd assignment i think). My version of python (2.7.3) doesn't seem to know what to do with '%'. e.g. if I do 15%3 it returns 0. Can anyone explain what's happening here? Have I downloaded the wrong version? What command can I use without starting again with 2.5.4? Many thanks :)

  • This Question is Open
  1. TuringTest
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    well 15%3 is zero, because 3*5=15 so there is no remainder do you still get zero for 12%5 ???

  2. asrowley
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Okay, I'm clearly missing something major here. I'm looking for a command (operator?) whereby I can do ... 12/5 and get 2.4 (a rational number?) and not 2 (an integer). I gathered from the lectures that '%' was the way to do this but, as you say, this means something else entirely. So two questions - 1. What does '%' do? and 2. How can I get do division and get numbers with decimals? As you can probably tell, maths is not my strong suit :)

  3. MicroBot
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    well its not so much maths here but the way a programming enviroment sees maths. taking you exsample im going to give you different ways to do the division. 1: 12/5 =2 it is True as what you do is an integer division. 2: 12.0/5.0 = 2.4 this is called a float division. 3. 12%5 =2 but 2 here is NOT the RESULT of an integer division but the REMAINDER of that integer division. eg 10%3=1 because 10/3=3 --> 3*3=9 this means we have a remainder of 10-9=1 hope this helps!:)

  4. asrowley
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for your help MicroBot - this does really help and has cleared up the issue with the way Python see the different division types. :)

  5. MicroBot
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    You are welcome!:) Ask whenever you need help:)

  6. victorl2
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    when you expect any result rather than a integer number as 1 ,2 ,3... you need use the float type as our friend "MicroBot" said. 2 is "integer" , 2.0 is "float"

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy