You are on page 1of 2

King Abdulaziz University

The Applied College

ACCS 102: Introduction to Programming


Assignment 2
Assignment Learning Outcomes:

By the end of this assignment, you will be able to:


1. Recognize the use of the for loop
2. Use different methods on Python lists

Scenario:
Using a list and For loop, write a Python program that asks a user to enter a city 3 times and displays
the list of cities.

Instructions Points
1 Create an empty list 1
2 Use For loop (counter = 3) 2
3 Ask the user to enter a city 1
4 Add the city to the list 2
5 Display the list 1
Total 7

Expected output:
Enter a city: Jeddah
Enter a city: Makkah
Enter a city: Riyadh
The list is: ['Jeddah', 'Makkah', 'Riyadh']

Requirements:
1. Download the assignment document.
2. Copy and paste the Python code into the assignment document.
3. Provide a screenshot for the console screen in the assignment document.
4. Submit the assignment document.

Page 1 of 2
King Abdulaziz University
The Applied College

# Create an empty list


cities = []

# Use For loop (counter = 3)


for i in range(3):
# Ask the user to enter a city
city = input("Enter a city: ")

# Add the city to the list


cities.append(city)

# Display the list


print("The list is:", cities)

Page 2 of 2

You might also like