Saturday, May 4, 2019

Girls Who Code For Loop by Lou Person

The for loop is code that will loop through a site of numbers or characters.  Starting with the last program you created last ( http://blog.louperson.com/2019/04/lou-person-stem-girls-who-code-select.html ), add the following code to the program and upload it to the cgi-bin directory:

for x in range(10):
    print(x)

What happens after you process the form that calls this program? 

Next, after you print x, print a <br> so each number prints on a different line.

When you are done with that, work with a partner to build an IF statement to determine if the number is even or odd and print even or odd next to the number.

Hint: You'll want to use the % operator (which is not division, it is called the modulo operator % which will return 0 if even and 1 if odd.

Why are you modulo by 2?

Here is information on operators: https://www.w3schools.com/python/python_operators.asp

Here is a hint:

if x % 2 == 0:                  
        print("even")           
if x % 2 == 1:              
        print("odd")

Also, experiment with the for loop, here is more information: https://www.w3schools.com/python/python_for_loops.asp