This document contains summaries of two lectures on updating variables and iteration in Python programming. Lecture 17 discusses reassignment of variables to new values and updating variable values based on their previous values. Lecture 18 introduces for and while loops for automating repetitive tasks, the break keyword to terminate loops, and calculating square roots through iterative approximation. The document provides examples of reassigning variable values, updating variables, using for and while loops, and computing square roots with the iterative formula.
5. • More than one assignment
to the same variable.
• A new assignment makes
an existing variable refer to
a new value (and stop
referring to the old value)
Reassignment
a = 5
Print (a) is 5
a = 6
Print (a) is 6
7. Updating variables
• The new value of the
variable depends on
the old.
x = x + 1
• Get the current value
of x, add one, and then
update x with the new
value.
• Before you can update a
variable, you have to
initialize it, usually with
a simple assignment:
x = 5
x = x+1
13. for & while statement
• Computers are often
used to automate
repetitive tasks.
• Repeating identical or
similar tasks without
making errors
• Two main loop
statements are
available.
for
while
15. Break
• The break is a keyword in
python which is used to
terminate the loop.
• It breaks the inner loop first
and then proceeds to outer
loops.
while True:
line = input('Enter line to print: ')
if line == 'Exit':
break
print (line)