Python 3.4.1.6 LAB: The basics of lists

 3.4.1.6 LAB: The basics of lists

The basics of lists

The basics of lists

If you're taking PCAP - Programming Essentials In Python , you may have encountered this question 3.4.1.6 LAB: The basics of lists.

Objectives

Familiarize the student with:

using basic instructions related to lists;

creating and modifying lists.

Scenario

There once was a hat. The hat contained no rabbit, but a list of five numbers: 1, 2, 3, 4, and 5.

Your task is to:

write a line of code that prompts the user to replace the middle number in the list with an integer number entered by the user (Step 1)

write a line of code that removes the last element from the list (Step 2)

write a line of code that prints the length of the existing list (Step 3).

Ready for this challenge?

Solution Code

hat_list = [12345]  # This is an existing list of numbers hidden in the hat.
# Step 1: write a line of code that prompts the user
# to replace the middle number with an integer number entered by the user.
user_number = int(input("Please Enter an integer: "))
hat_list[2] = user_number
# Step 2: write a line of code that removes the last element from the list.
del hat_list[-1]
# Step 3: write a line of code that prints the length of the existing list.
print(f"The length of the list is: {len(hat_list)}")
print(hat_list)

=================================================================================

Follow the Python page on the Blog to be the first to know

Comments

Popular posts from this blog

فرصتك للدراسة في ألمانيا: منحة ممولة بالكامل لطلاب الدراسات العليا

How to Deactivate Screen Reader in Kali Linux

Murphy's Law: Expect the Unexpected

Python 3.2.1.14 LAB: Essentials of the while loop

Data Analysis Roadmap 2026: From Excel Lover to Python-Powered Analyst

7 Reasons Why You Need to Learn English

Prefixes vs Suffixes ? What are they?

15 Python Builtin-Functions You Need to Master as a Beginner

ما هو يوم التأسيس للدولة السعودية؟

ROI