nick34992
1/11/2017 - 11:35 PM

MITx 600.1x | Week 1 | Python Basics | 2. Core Elements of Programs | Exercise: while: Item 2

MITx 600.1x | Week 1 | Python Basics | 2. Core Elements of Programs | Exercise: while: Item 2

#!/usr/bin/python3

print('Hello!')
num = 10  # initialize in global namespace
counter = 0
while num > -1:  # define loop
    print('num =', num, '| num counter subtracted:', counter)
    num -= 2  # counter subtracts
    counter += 2  # counter adds
'''
MITx 600.1x | Week 1 | Python Basics | 2. Core Elements of Programs | Exercise while: Item 2

Hello!
num = 10 | num counter subtracted: 0
num = 8 | num counter subtracted: 2
num = 6 | num counter subtracted: 4
num = 4 | num counter subtracted: 6
num = 2 | num counter subtracted: 8
num = 0 | num counter subtracted: 10
'''