3. What is a Computer Langugage?
4. Quiz Games and If Statements.
5. Guessing Games with Random Numbers and Loops.
In [3]:
help("for")
Syntax:
"for" target_object "in" expression_list ":"
"body of the loop"
Points of Interest:
1. Target_object ; Any Python object:
2. Expression_list ; is eval only once.
When eval; yields an iterable object.
Consequently; An "iterator" is created.
3. Loop Body / Suit ; is executed once for each item, provided by the iterator.
Performs nessecery ops on expressions within the loop body, mainly assignments.
When the items are exhausted, the iterator raises a "StopIteration" exception.
The suite moves to "else" clause, if present, is executed, and the loop terminates.
In [7]:
%%HTML
<iframe width="800" height="250" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=for%20i%20in%20range(5%29%3A%0A%20%20%20%20print(%22I%20will%20not%20bow!%22%29&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=false&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe>
range() function
The python
In [11]:
help("range")
"""
Syntax: range( start, stop, stepsize ) -> range object.
"""
# a simple example
for i in range(5):
print("Hello Again!")
print("Ok bye!")