nick34992
1/11/2017 - 9:37 PM

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

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

#!/usr/bin/python3

num = 10
counter = 0

while True:
    if num < 7:
        print('num =', num, '| loop breaks | double-indented')
        break
    print('num =', num, '| counter subtracted:', counter, '| single-indented')
    num -= 1
    counter += 1
print('num =', num, '| zero-indented | outside of loop')

'''
MITx 600.1x | Week 1 | Python Basics | 2. Core Elements of Programs | Exercise 4 - Item 4

num = 10 | counter subtracted: 0 | single-indented
num = 9 | counter subtracted: 1 | single-indented
num = 8 | counter subtracted: 2 | single-indented
num = 7 | counter subtracted: 3 | single-indented
num = 6 | loop breaks | double-indented
num = 6 | zero-indented | outside of loop
'''