0% found this document useful (0 votes)
55 views4 pages

Lab Manual - AETN2302 - L6 (Lists-I)

This document provides instructions for a lab on logic and bit operations and lists. It outlines objectives, equipment, and 3 parts to the lab involving bit shifting, list operations, and modeling changes to the Beatles band membership.

Uploaded by

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

Lab Manual - AETN2302 - L6 (Lists-I)

This document provides instructions for a lab on logic and bit operations and lists. It outlines objectives, equipment, and 3 parts to the lab involving bit shifting, list operations, and modeling changes to the Beatles band membership.

Uploaded by

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

End of

Lab 6 – “Logic and bit operations” and “Lists”


Student Name Date: 19/10/2023

Lab Instructions and Rules

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

Sample input: 17*4 = 68, 17 // 2 = 8, 17 % 2 = 1


Your code
var=int(input())
var_right=var>>1
var_left=var<<2
var_right2=var<<1
var_left2=var-(var_right<<1)
print(var,"*4=",var_left,",",var,"//2=",var_right,",",var,"%2=",var_left2,)

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).

Test your code using the data we've provided.

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:

 step 1: create an empty list named beatles;


 step 2: use the append() method to add the following members of the band to the
list: John Lennon, Paul McCartney, and George Harrison;
 step 3: use the for loop and the append() method to prompt the user to add the following
members of the band to the list: Stu Sutcliffe, and Pete Best;
 step 4: use the del instruction to remove Stu Sutcliffe and Pete Best from the list;
 step 5: use the insert() method to add Ringo Starr to the beginning of the list.

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

Part 1: Program setup 25


Part 2: Code 50
Part 3: output verification 25
Total Packet Tracer Score 100

End of document REFERENCES: Cisco Network academy

You might also like