CS115_Lab05
CS115_Lab05
Lab 05
Lab Objectives: Tuples, Lists, Dictionaries
Notes:
● Upload your solutions as a single .zip file to the Lab05 assignment for
your section on Moodle. You must use the following naming
convention: Lab05_Surname_FirstName.zip where Surname is your
family name and FirstName is your first name.
● You should only use functionality covered in CS115 in your solution.
● Include a docstring for your functions.
a. Write a function pair_sum() that takes a list of integers and returns a new list
where each pair of integers from the original list has been replaced by the sum of
that pair.
b. Write a script that initializes an integer list and then call the pair_sum()
function to store the pair sums in a new list and display it.
b. Write a script that initializes a tuple and finds its tuple elements using the
select_tuples() function. Display the returned tuple.
Sample Run 1:
input tuple: (5, 'ab', (1, 4), 4.3, 'xyz', (2, 'a'))
tuples in input tuple: ((1, 4), (2, 'a'))
Sample Run 2:
input tuple: (5, 'ab', (1, 4, (3, 5)), 4.3, 'xyz', (2, 'a', [2, 7]))
tuples in input tuple: ((1, 4, (3, 5)), (2, 'a', [2, 7]))
Sample Run 3:
input tuple: (5, 'ab', [1, 4, (3, 5)], 4.3, 'xyz', (2, 'a', (2, 7)))
tuples in input tuple: ((2, 'a', (2, 7)),)
Q3: Write a program Lab5_Q3.py, to track all customers and accounts of a customer (by
her/his customer number). Your program should store the list of customers and accounts in a
dictionary, where the key is the customer number and the value is a list of tuples (account id,
branch and balance). Your program should define the following functions:
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 2
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 1
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 2
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 1
Enter customer number: 5
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 3
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 2
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 2
1)Add Customer
2)Search Customer
3)Add Account
4)Quit
Enter Choice: 4
Program Ended....