Skip to content

Introduction to Python — Session 4

In this session we cover:

  • Lists
  • For loops
  • Ranges

Write your code

Questions

Section A

  1. Create the following list of items: Apples, Cherries, Pears, Pineapple, Peaches, Mango. Then print the list
  2. Add "Grapes" to the list and print the list
  3. Change "Pears" to "Strawberries" and print the list
  4. Remove "Apples" from the list and print the list
  5. Print out the current length of the list
  6. Order the list alphabetically
  7. Print out the list again

Section B

  1. Loop through the list you created in section A and print each item out
  2. Print the numbers 1 to 100 (including the number 100)
  3. Print all odd numbers from 1 to 100
  4. The modern olympics started in 1896, print the years they have been held (bonus points to skip 1916, 1940, 1944)
  5. Create a list of ten random numbers. Loop through your list and count the number of even numbers and the number of odd numbers.
  6. Create a list of five names. Write a loop that will print "Hello" plus each name in the list.
  7. Create a loop to go through each letter of the word "supercalifragilisticexpialidocious".
  8. Create a list of 5 numbers. Write a for loop which appends the square of each number to the new list.
  9. Create a list with five names in. Write a for loop which appends Dr. to each name in the new list.
  10. FizzBuzz – Write a program that prints the numbers from 1 to 100. For multiples of three, print "Fizz" instead of the number and for multiples of five, print "Buzz". For numbers which are multiples of both three and five, print "FizzBuzz". E.g:
    1
    2
    Fizz
    4
    Buzz
    Fizz
    7
    8
    Fizz
    Buzz
    11
    Fizz
    13
    14
    FizzBuzz

Answers

See the code for each answer on our GitHub!