In [1]:
# Write a for loop so that every item in the list is printed.

lst=["koala", "cat", "fox", "panda", "chipmunk", "sloth", "penguin", "dolphin"]
#Type your answer here.

for x in lst:
    print(x)
koala
cat
fox
panda
chipmunk
sloth
penguin
dolphin
In [17]:
# Write a for loop which print "Hello!, " plus each name in the list. i.e.: "Hello!, Sam"

lst=["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]
#Type your code here.

for x in lst:
    print("Hello!,", x)
Hello!, Sam
Hello!, Lisa
Hello!, Micha
Hello!, Dave
Hello!, Wyatt
Hello!, Emma
Hello!, Sage
In [3]:
# Write a for loop that iterates through a string and prints every letter.

str="Antarctica"
#Type your code here.

for x in str:
    print(x)
A
n
t
a
r
c
t
i
c
a
In [31]:
# Type somecode inside the for loop so that counter variable named c is increased by one each time loop iterates. 
#Can you guess how many times it will add 1?.

str="Civilization"

c=0
for i in str:   
    #sourcecode will go below
    c += 1
    print(c)
    #sourcecode will go above
1
2
3
4
5
6
7
8
9
10
11
12
In [34]:
# Using a for loop and .append() method append each item with a Dr. prefix to the lst.
#Info on the .append() method can be found at https://www.w3schools.com/python/ref_list_append.asp

lst1=["Phil", "Oz", "Seuss", "Dre"]
lst2=[]

#Type your answer here.

for x in lst1:
    lst2.append(x)
    print("Dr.", x)
Dr. Phil
Dr. Oz
Dr. Seuss
Dr. Dre
In [43]:
# Write a for loop which appends the square of each number to the new list.

lst1=[3, 7, 6, 8, 9, 11, 15, 25]
lst2=[]

#Type your answer here.
for x in lst1:
    lst2.append(x)
    print(x**2)
9
49
36
64
81
121
225
625
In [50]:
# Write a for loop using an if statement, that appends each number to the new list if it's positive.

lst1=[111, 32, -9, -45, -17, 9, 85, -10]
lst2=[]

#Type your answer here.
for x in lst1:
    if num > 0:
        lst2.append(x)
        print(abs(x))
111
32
9
45
17
9
85
10
In [51]:
# Write a for loop which appends the type of each element in the first list to the second list.

lst1=[3.14, 66, "Teddy Bear", True, [], {}]
lst2=[]

#Type your answer here.
for x in lst1:
    lst2.append(x)
    print(type(x))
<class 'float'>
<class 'int'>
<class 'str'>
<class 'bool'>
<class 'list'>
<class 'dict'>
In [ ]: