Introduction to Python — Session 4
In this session we cover:
- Lists
- For loops
- Ranges
Write your code
Questions
Section A
- Create the following list of items: Apples, Cherries, Pears, Pineapple, Peaches, Mango. Then print the list
- Add "Grapes" to the list and print the list
- Change "Pears" to "Strawberries" and print the list
- Remove "Apples" from the list and print the list
- Print out the current length of the list
- Order the list alphabetically
- Print out the list again
Section B
- Loop through the list you created in section A and print each item out
- Print the numbers 1 to 100 (including the number 100)
- Print all odd numbers from 1 to 100
- The modern olympics started in 1896, print the years they have been held (bonus points to skip 1916, 1940, 1944)
- Create a list of ten random numbers. Loop through your list and count the number of even numbers and the number of odd numbers.
- Create a list of five names. Write a loop that will print "Hello" plus each name in the list.
- Create a loop to go through each letter of the word "supercalifragilisticexpialidocious".
- Create a list of 5 numbers. Write a for loop which appends the square of each number to the new list.
- Create a list with five names in. Write a for loop which appends Dr. to each name in the new list.
- 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