python-ecology-lesson icon indicating copy to clipboard operation
python-ecology-lesson copied to clipboard

More explanation of modulo

Open maneesha opened this issue 6 years ago • 4 comments

The episode Short Introduction to Programming in Python notes that

We can perform mathematical calculations in Python using the basic operators +, -, /, *, %:

I don't think most people would consider modulo to be a basic operator. I would recommend some more explanation of what modulo does.

maneesha avatar Dec 10 '19 13:12 maneesha

I don't think most people would consider modulo to be a basic operator.

I agree. Would dropping it here be a reasonable alternative to explaining it?

maxim-belkin avatar Dec 10 '19 15:12 maxim-belkin

Either way would work from my perspective. It could be useful to know, so it may be worth introducing. However, that may make this lesson longer so I'm fine dropping it as well.

maneesha avatar Jan 18 '20 19:01 maneesha

There is a good example which shows either both of things which I miss here: the if/else statement and the example for modulo:

There is one common use for the Modulo Operator: to find even or odd numbers eg in a range 1 to 10:

for number in range(1, 10):
    if(number % 2 != 0):
        print(number)

The lesson shows the boolean type but no example for the usage. If/else condition would be helpful to introduce at this point. Thus, both topics are great to include here.

nettic avatar Feb 17 '20 16:02 nettic

I would suggest to add the example of finding even or odd numbers where we introduced a list.

https://datacarpentry.org/python-ecology-lesson/01-short-introduction-to-Python/#lists

gnguyen27 avatar Feb 17 '20 20:02 gnguyen27