logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    Bonnie Ma
    Oct 03, 2021
      ·  Edited: Oct 10, 2021

    Class 4 - Back for More

    in Python for ACSL

    Hi, everyone! I'm a bit busy this week so lesson notes are gonna be briefer. Reach out for more detailed explanations if you need them, though.


    -Bonnie

     

    Review:

    Boolean expressions, Boolean operators, if statements, comparison operators


    For Loops:

    Syntax, nested for loops


    Class Problems/Homework - Questions 6-7 (7 is hard, if it's too hard wait until the solutions come out on Saturday night or ask for help)


     

    FOR LOOPS

    range() is a built-in function in Python that creates a list in increasing order based off of three parameters: start, stop, and skip. By default, start is 0, and skip is 1. Start is the number you want the list to start from. Stop is the number that the list will stop right before reaching it. Skip is the interval you want the list to increase by (it can be negative for decreasing order).


    print(range(10))

    ----------------------

    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    ^Why does the number I give for the stop parameter never included in the list? Count the numbers in that list. Since in programming we use 0 to refer to the first item in a list, starting from 0 and counting to 9 creates the 10 item list that you requested. Using range(num) creates a list of len() = num.


    NESTED FOR LOOPS (not covered in class yet, read only if you want)


    Nested for loops are loops inside loops. Each iteration of the outside loop will make its nested loop run completely each time.


    for i in range(10):

    for j in range(10):

    print("hello")


    ^ In this example, "hello" will be printed 100 times.

    ^ Also, the variables you initialize to iterate through nested loops can't be the same. Across separate loops it's fine. But nested loops are connected and the program will get confused if you use duplicate variable names.


    That's all, folks. See ya

    -Bonnie (and Alan)



    0 comments
    0 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners