Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 24 Online
OpenStudy (anonymous):

In handout, Lecture 5, when defining the divisors there is some code in which I do not understand it's function. It is the percent sign (%) after the x. How does that work? Here is the code : x = 100 divisors = () for i in range(1,x): if x%i == 0: divisors = divisors+(i,) print divisors

OpenStudy (anonymous):

The % is the modulus operator, which gets the remainder of division. For example 7 divided by 2 is 3 with a remainder of 1. Thus 7 % 2 = 1. When a number perfectly divides a number, then it will have a remainder of 0. For example 4 / 2 = 2 remainder 0. You can use the % to determine factors or divisors of a number.

OpenStudy (anonymous):

From i = 1 to 100, 100 will be divided by i, the remainder is x%i will equal zero if and only if the division is clean. Suffice to say, this function finds all dividers for "100". Matlab output for 100%i == 0: 1 2 4 5 10 20 25 50 100

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!