Loops in Python (Python Part 5)

This class will teach you about While and For loops in Python.

  • 00:00 Intro
  • 07:01 While Loops
  • 12:08 While Loop Example
  • 23:57 For Loop
  • 25:03 For Loop Example
  • 29:39 Final Thoughts

while.py

x = 1

while x < 10:
    print(f'Iteration {x}')
    x += 1

payment.py

total = 10000
payment = 212
months = 0

while total > 0:
    print(f'Owed: {total}')
    total = total - payment
    months += 1

years = months / 12
print(f'Paid off in {years} years')

for.py

attendees = ['tom', 'sue', 'fred', 'tim']

for name in attendees:
    print(name)

class-list.py

attendees = [['sue', 'girl', 'large'], 
             ['bob', 'boy', 'small'], 
             ['phil', 'boy', 'large'], 
             ['barb', 'girl', 'small']]

for x in attendees:
    if 'small' in x and 'girl' in x:
        print(x)

Be the first to comment

Leave a Reply