0% found this document useful (0 votes)
6 views5 pages

Python Skills Worksheet Using Lists

The document provides a series of programming tasks focused on using lists in Python. It includes exercises for predicting outputs, modifying lists, and creating programs for managing friends' names and restaurant dishes. Additionally, it outlines methods for manipulating lists and offers a trace table for understanding list changes.

Uploaded by

aaravthirani97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Python Skills Worksheet Using Lists

The document provides a series of programming tasks focused on using lists in Python. It includes exercises for predicting outputs, modifying lists, and creating programs for managing friends' names and restaurant dishes. Additionally, it outlines methods for manipulating lists and offers a trace table for understanding list changes.

Uploaded by

aaravthirani97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Worksheet Using lists

Task 1
1. DO NOT RUN THIS PROGRAM YET!Predict the output you would see if you were to run this program.

friends = ["Fred","Paul","George","Ringo"]print("One of my friends is called


",friends[1])

Prediction: One of my friends is called Paul

1. Alter the program so that it will print out “Ringo” instead.(Note: You must use the list to do this, don’t cheat
and just write in “Ringo”!)

print(“One of my friends is called”,friends [3])

1. The first name in the list is wrong. Add a new line to the program that will change the first name from
“Fred” to “John”.Add this line to the very end of the program so that you can see if it has worked.

friends = ["Fred ", "Paul ", "George","Ringo"]

friends[0]=”John”

print(friends)

1 Th f ll i d ill t t li t f 4 th k th f t l i th li t
1. The following code will create an empty list of 4 names, then ask the user for a name to place in the list.
The last line is just there so we can see what the list looks like at the end.

friends = [None] * 4name = input("Enter the name of a friend: ")friends[0] = name

name1=input(“Enter Name:”)

name2=input(“Enter Name:”)

name3=input(“Enter Name:”)

friends[1]=name1

friends[2]=name2

friends[3]=name3

print(friends)Add more code that will ask the user for more names to complete the list. The last line should
still print the complete list out.

1. Write a program for a takeaway restaurant. It should start by asking the user to enter 5 dishes that they
sell. The program should then print out the list of dishes so the user can check it is right.

1. Add to the previous program so that, once finished, the user should be asked to enter a number for which
dish they want. The program should then print out the name of the dish they have chosen.Hint:
Remember to use int(input(…))

dishes = []

for i in range(5):

dish = input(f"Enter dish {i + 1}: ")

dishes.append(dish)

print("Here is the list of dishes you entered:")

print(dishes)

dish_number = int(input("Enter the number of the dish you want (1-5): "))

if 1 <= dish_number And <= 5:

print(f"You have chosen: {dishes[dish_number - 1]}")

else:
print("Invalid number! Please enter a number between 1 and 5.")

Extension Task:

Create a program for a cinema to keep a list of the latest films being screened. The program should start by
presenting the user with a menu:

1. Reset list
2. View entire list
3. View one item
4. Edit list
5. Quit

Option 1 should create a blank list of 6 films.

Option 2 should print the entire list in one go.

Option 3 should ask which item the user wants to see (by number) and display that film.

Option 4 should ask the user which item they want to change and what film they want to replace it with. The
program should then replace that item.

Option 5 should exit the program.

The program should repeat (using a WHILE loop) until the user chooses option 5.
Task 2

Method Description

append(value) Add a new value to the end of a list

insert(index,value) Inserts a value at a point in the list and moves other items along one

list[index]=value Changes the list value at a given index

pop(index) Removes a particular index value from a list

pop() Removes the last index value from a list

remove(value) Removes a given value from a list

Use the blank trace table below to work out the value of the list at each line of the program.
List index 0 1 2 3 4 5 6

word =["b","e","a","k"]

word[3] = "n"

word.append("s")

word[3] = "d"

word.insert(1,"r")

word[0] = "t"

word.remove ("t")

word[1] = "o"

word.pop()

print(word)

You might also like