Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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 :)

MIT 6.00 Intro Computer Science (OCW)
See more answers at
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

well 15%3 is zero, because 3*5=15 so there is no remainder do you still get zero for 12%5 ???
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 :)
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!:)

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Thanks for your help MicroBot - this does really help and has cleared up the issue with the way Python see the different division types. :)
You are welcome!:) Ask whenever you need help:)
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"

Not the answer you are looking for?

Search for more explanations.

Ask your own question