datacarpentry / python-ecology-lesson

Data Analysis and Visualization in Python for Ecologists
https://datacarpentry.org/python-ecology-lesson
Other
160 stars 310 forks source link

More explanation of modulo #424

Open maneesha opened 4 years ago

maneesha commented 4 years ago

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.

maxim-belkin commented 4 years ago

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?

maneesha commented 4 years ago

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.

nettic commented 4 years ago

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.

gnguyen27 commented 4 years ago

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