Python For Loop Exercises
Let’s check out some exercises that will help you understand Python’s For Loops better.
Exercise 8-a
Write a for loop so that every item in the list is printed.
Exercise 8-b
Write a for loop which print "Hello!, " plus each name in the list. i.e.: "Hello!, Sam"
Exercise 8-c
Write a for loop that iterates through a string and prints every letter.
Exercise 8-d
Type a code 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?.
Exercise 8-e
Using a for loop and .append() method append each item with a Dr. prefix to the lst.
Exercise 8-f
Write a for loop which appends the square of each number to the new list.
Exercise 8-g
Write a for loop using an if statement, that appends each number to the new list if it's positive.
Exercise 8-h
Using for loop and if statement, append the value minus 1000 for each key to the new list if the value is above 1000. i.e.: if the value is 1500, 500 should be added to the new list.
Exercise 8-i
Write a for loop which appends the type of each element in the first list to the second list.