UNIVERSITY EXAMINATIONS: 2021/2022
EXAMINATION FOR DEGREE IN BACHELOR OF SCIENCE
SOFTWARE DEVELOPMENT/INFORMATION SECURITY AND
FORENSICS
BSD 2302/BISF 3106: PYTHON PROGRAMMING
MODE: PART TIME/FULL TIME/DISTANCE LEARNING
ORDINARY EXAMINATIONS
DATE: DECEMBER, 2021 TIME: 2 HOURS
INSTRUCTIONS: Answer question ONE COMPULSORY and ANY OTHER TWO questions
QUESTION ONE [20 MARKS] -COMPUSORY
a). You are required to develop a python program that repeatedly asks the user to enter
product names and prices. Store all of these in a dictionary whose keys are the product
names and whose values are the prices. When the user is done entering products and
prices, the program allows them to repeatedly enter a product name and print the
corresponding price or a message if the product is not in the dictionary. (10 Marks)
b). Write a python program to ask the user to enter a temperature in Celsius. The program
should print a message based on the temperature:
• If the temperature is less than -273.15, print that the temperature is invalid because it
is below absolute zero.
• If it is exactly -273.15, print that the temperature is absolute 0.
• If the temperature is between -273.15 and 0, print that the temperature is below
freezing.
• If it is 0, print that the temperature is at the freezing point.
• If it is between 0 and 100, print that the temperature is in the normal range.
• If it is 100, print that the temperature is at the boiling point.
• If it is above 100, print that the temperature is above the boiling point (10 Marks)
QUESTION TWO [15 MARKS]
You are required to develop a program that asks the user to enter three numbers. These values of
these numbers are read by a function called getNumber () which then passes their values to
another function called Calculator () which will calculate the average and the total for these
values then return the result to the calling function.
a). Design a pseudo code for this case. (7 Marks)
b). Convert the pseudo code to a python program. (8 Marks )
QUESTION THREE [15 MARKS]
“There is a proposal to come up with a simple system which will have two classes. One of the
class is the base class while the other is the sub class. The base class will store three data
members namely product name, quantity and price. The sub class will have two member
methods, one of the method will read the values of the data members then pass those values to
another method which calculates the cost of the product inclusive of the value added tax (VAT)
and displays the result”.
a). Design an UML class diagram for this case. (7 Marks)
b). Implement the design above using python and instantiate the class with at least one
object. (8 Marks )
QUESTION FOUR [15 Marks]
You are required to develop POS app. The app will have a class called Product. The class should
have fields called name, amount, and price, holding the product’s name, the number of items of
that product in stock, and the regular price of the product. There should be a method get price()
that receives the number of items to be bought and returns a the cost of buying that many items,
where the regular price is charged for orders of less than 10 items, a 10% discount is applied for
orders of between 10 and 99 items, and a 20% discount is applied for orders of 100 or more
items. There should also be a method called do purchase() that receives the number of items to
be bought and decreases amount by that much. Based on this case.
a). Draw a UML class diagram for this scenario. (7 Marks)
b). Write a python program to implement the design. (8 Marks)