Lab Manual - AETN2302 - L6 (Lists-I)
Lab Manual - AETN2302 - L6 (Lists-I)
1. If you arrive later than 10 minutes after the lab started, you will not be allowed to
do the lab.
3. There is no time allocated to redo any missed labs.
4. Absence from labs will result in a grade of zero unless a written medical excuse is
provided.
OBJECTIVES
1. become familiar with the lists;
2. become familiar with Logic and bit operations;
EQUIPMENT
1. Pcs
2. Sandbox
PART I:
Scenario: Assume you live in a world where there is no calculator but you still want to be able
to multiply a number by a power of 2 (e.g. 2, 4, 8…) and/or find the result of integer division by
that number. It is assumed that we can only shift bits within a binary number to left or right (this
is what electronic circuits can do!). Write a program that accepts a number (called ‘var’) at the
input and calculates 4*var and var//2 and var%2 at the output. For the provided test data, try the
output.
Also for the same input number, find the binary equivalent of ‘var’, manually apply the right and
left shift to it, and change it back to decimal. This will prove that you have the right take on what
is going on.
Test Data
Sample input: 17
Output
17
17 *4= 68 , 17 //2= 8 , 17 %2= 1
18
18 *4= 72 , 18 //2= 9 , 18 %2= 0
PART II
Scenario: There once was a hat. The hat contained 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).
Your code
my_list = [1,2,3,4,5]
my_list[2] = int(input("enter a number"))
print(my_list)
del my_list [4]
print(my_list)
print(len(my_list))
Output
enter a number15
[1, 2, 15, 4, 5]
[1, 2, 15, 4]
4
PART III
Scenario: Write a program that reflects the changes of the Beatles members (The Beatles were
one of the most popular music groups of the 1960s). Your task is to:
Your code
beatles = []
beatles.append("John Lennon")
beatles.append("Paul McCartney")
beatles.append("George Harrison")
for i in range(2):
beatles.append(input("Name"))
del beatles[-1]
del beatles[-1]
beatles.insert(0,"Ringo Star")
print(beatles)
Output
Name MOHAMED
Name AHMED
['Ringo Star', 'John Lennon', 'Paul McCartney', 'George Harrison']
Suggested Scoring Rubric
Possible Earned
Activity Section Points Points