Skip to content

Lesson 6

List

Pseudo code

# Print a list of names by using list data structure

Scott
Mo
Faz
CJ
Rachel
names = ["Scott", "Mo", "Faz", "CJ", "Rachel"]

for name in names:
    print(name)

Files

Pseudo code

# Print a list of names by using file system. Store the expected outout in a file called names.txt

Kaelin
Faz
CJ
Rachel
Scott
Mo
f = open("names.txt")

i = 0

while True:
    name = f.readline()
    # check to see if we reached the end of the line
    if not name:
        break

    # only print the name if i is even number
    if i % 2 == 0:
        print(name, end="")

    i = i + 1