-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path3.4.1.6Lab.py
46 lines (31 loc) · 1.16 KB
/
3.4.1.6Lab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Estimated time
5 minutes
Level of difficulty
Very easy
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?
hat_list = [1, 2, 3, 4, 5] # 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.
# Step 2: write a line of code that removes the last element from the list.
# Step 3: write a line of code that prints the length of the existing list.
print(hat_list)
'''
hat_list = [1, 2, 3, 4, 5]
# Step 1:
hat_list[2] = int(input("Enter a number to replace the middle element: "))
# Step 2:
hat_list.pop()
# Step 3:
print(len(hat_list))
print(hat_list)