A community for students.
Here's the question you clicked on:
 0 viewing
asrowley
 2 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 :)
asrowley
 2 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

TuringTest
 2 years ago
Best ResponseYou've already chosen the best response.0well 15%3 is zero, because 3*5=15 so there is no remainder do you still get zero for 12%5 ???

asrowley
 2 years ago
Best ResponseYou've already chosen the best response.0Okay, 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 :)

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.3well 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 109=1 hope this helps!:)

asrowley
 2 years ago
Best ResponseYou've already chosen the best response.0Thanks for your help MicroBot  this does really help and has cleared up the issue with the way Python see the different division types. :)

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.3You are welcome!:) Ask whenever you need help:)

victorl2
 2 years ago
Best ResponseYou've already chosen the best response.0when 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"
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.