Professional Documents
Culture Documents
Leenon Matsiwe
Programming principles and Application
HMPH
LAB WORK
QUE1.Create a program that asks the user to enter their name, surname, registration
number, program, level and their age. Print out a message addressed to
them that tells them the year that they will turn 100 years old. Note: for this
exercise, the expectation is that you explicitly write out the year (and
ANSWER
QUE1,2. Ask the user for a number. Depending on whether the number is even or
odd, print out an appropriate message to the user.
Answer
QUE 2. Pen a program that asks a user to enter amount of gross income and calculate the
RTGS30000.
Write a program for a Bank Balance class that ask a user to enter bank balance and
maintains at least a RTGS it should attract interest for that month. If it happens the
customer withdraws more than the bank balance then the bank will attract a
penalty of 8 RTGS. If the withdraw amount is greater than the balance then the
program should ask the customer whether he wants to overdraw or not. If customer
opts for a no on overdraw option then the balance does not change.
Answer
5QUE.4 Pen a program that allow user to enter 7 temperatures as decimals. The
temperature, reads in 7 temperatures and shows temperatures which are above and
Answer
QUE5. Write a Python program to calculate the amount of money Johnny takes home after
spending some of his pocket money at the school’s tuck shop. He started with
an amount such as $50 pocket money. He decided to buy a packet of crisps for
example with ($4), a hotdog for example ($6) and a bottle of juice for a value ($5).
VAT was not included in the price and still had to be added to his total.t
Calculate how much money Johnny spent and how much money he had left over.
Answer
QUE.6 Write a program that allows the user to enter his/ her height in meters. Send this
value to a class method called Height. The method should then convert the user’s
ANSWER
QUE.7 Create a class called Car. The data fields must be the car’s make, model and top
speed. Write a constructor and the get and set functions for the class. Also, write a
method that will determine the type of classification of the class. If the top speed is
&Get; 250 km then it is a Super Car, if the top speed is &let; 100km then it is a Jalopy
ANSWER
QUE.8Write a python program to analyses the rainfall in Zimbabwe
Input:
Process:
Output:
• Month name;
• Season (Winter/Summer);
• The total rainfall for the month is &get; or &let; than average rainfall.
ANSWER
QUE.9 Write a program that allows the user to enter any number of integer values
continuously (in any order) until the user enters 999. Display the sum of the values
You should have method to enter numbers of data type int and a method to display
the sum which returns nothing, declare another method check Number which returns
a Boolean. Show how you will invoke the methods in the main.
ANSWER
QUE.10 Design a python method Ad dint () to add 5 integers that are read from the
keyboard and send the result, create another method called add Double to add 3
decimal numbers, create another method called Total Calculation to add the
integers and the decimals and show the result of the addition as a decimal. Use a
Question 11
Write a program in which a user can continue entering integers. The program should continue,
even if the user provides an invalid input. The user can type ‘q’ to quit the program.
Ans
Question 12
Create a list of numbers including integers and floats. Make sure that you have at least 5
numbers.
i) Using a for loop, print the content of this list.
ii) Print the elements from index position 2 to 5.
ANS
Question 13
Write a program to draw a red circle, then a yellow circle underneath it and a green circle
underneath that.
Question 14
Write a simple RPG character class. The character should have a name, a money pouch and an
inventory. The name should be stored as a string, the money pouch should be an instance of the
pouch from the previous exercise and the inventory should be a dictionary in which keys are item
names and values are the number of items held by the player. Ensure that there are methods for
adding items to, and removing items from, the inventory.
There should be a __str__ method that returns something that can be printed.
For example:
print player
Might display:
-------------------------
Duncan Disorderly
-------------------------
Money: 235 gold pieces
-------------------------
Knapsack contains:
Arrow: 12
ANS