>>     < >




In-class notes for 02/14/2014

CS 121B (CS1), Spring 2014

Submitted questions on assignments and technology

Upcoming

Submitted questions on readings

Functions

Syntax of languages

  • Syntax diagrams for input call, function call

Turtle graphics operations

Repetition with for

  • Recurring themes

  • Example: Instead of

        print("Hi", "Joe", "Please come to my party on Saturday!")
        print("Hi", "Amy", "Please come to my party on Saturday!")
        print("Hi", "Brad", "Please come to my party on Saturday!")
        print("Hi", "Angelina", "Please come to my party on Saturday!")
        print("Hi", "Zuki", "Please come to my party on Saturday!")
    
    we can accomplish the same computation using
        for name in ["Joe", "Amy", "Brad", "Angelina", "Zuki"]:
    	print("Hi", name, "Please come to my party on Saturday!")
    

  • Syntax diagram (syntax = rules for correct language expressions:

    • A Python3 iterator is an object that specifies repetition. In the example above, we are using

           ["Joe", "Amy", "Brad", "Angelina", "Zuki"]
      
      to specify the repetition.

    • A block is a segment of (Python3) code that is indented at the same level. Could be multiple statements in a block (here, could be multiple repetitions). /p>

  • Exercise: Modify code to print count of invitations

  • Exercise: Use turtle graphics to draw a 6-pointed star with 6 different colors (or shades).

  • Function range() -- produces an iterator of -- -- numbers

    • range(10)

    • range(1, 10)

    • range(1, 10, 2)

Python modules; objects

  • Complete Python3 documentation

  • Idea of module: reuse existing code instead of having to write it all yourself; hide the extensive details (abstraction)




< >