VIT1102 - Introduction to Programming
VU College
Lab 3 – Selection Structures
Open PyCharm and Create a Project called Lab3. In Lab3 create a Python package task1.
Ex1
Write a Python script, to read a number. If the number is positive, print “it is a positive
number!’. If the number is negative or zero, print appropriate messages.
Ex2
Write a Python script to calculate yearend Bonus payments. Bonus calculated as follows:
Job category 1 bonus = salary * 1.02
Job category 2 bonus = salary * 1.05
Job category 3 bonus = salary * 1.1
Your script must ask the user’s job category and salary. Then display the bonus. Format your
output.
Ex3
Implement and run Class Exercise 3, in lecture slides. Test your code. Once it is producing
desired outcomes, update your code as follows.
a. If the total ticket cost exceeds $100, add 10% discount to the total price.
b. Format all your outputs.
Additional Exercises
Ex4
Pet Happiness is an online dog food store. Write a program to calculate dog food purchases
from Pet Happiness. For each order made there is a standard delivery fee of $15. However,
orders over $100 receives free delivery.
Dogfood bags come in 3 pack sizes and cost as follows:
20kg (Large) - $100.00
15kg (Medium) - $70.00
5kg (Small) - $40.00
1
VIT1102 – Lab 3.docx
Oshadi Alahakoon 2020
VIT1102 - Introduction to Programming
VU College
In each bag size there are 2 varieties for adult dogs and puppy dogs. All puppy dog food bags
cost $5 less than the above given prices. Inputs and outputs from the program for 3
different inputs are given below for comparison.
Output 1
Output 2
Output 3
NOTE: Bag size and food type can be provided using lower or uppercase letters.
Third question displays the bag size, which was entered as the input of the previous
question. Total is formatted.
Ex5
2
VIT1102 – Lab 3.docx
Oshadi Alahakoon 2020
VIT1102 - Introduction to Programming
VU College
At a florist flowers are sold as follows:
5 stems pre-arranged bunch for $10
10 stems pre-arranged bunch $15
Any individual flower cost $2 each
Customers can purchase any combination of the above. Write a Python program to calculate
flower sales. If the total goes above $50, they can chose 2 additional flowers free. Sample
output look as follows.
Output 1
Output 2
Ex6
Write a python program to compare two integers and provide an output.
Your program should compare the two integers and print if they are;
Equal (==)
Greater than (>)
Less than (<)
Greater than or equal (>=)
Less than or equal (<=)
Not equal (!=)
Your programming output should look as follows.
Output 1
3
VIT1102 – Lab 3.docx
Oshadi Alahakoon 2020
VIT1102 - Introduction to Programming
VU College
Output 2
Ex7
Modify additional exercise (Book Store - purchase price calculation) program in Lab 2 to ask
the “number of days renting” only if they are renting books. Otherwise, the program should
just calculate the price of purchased books.
4
VIT1102 – Lab 3.docx
Oshadi Alahakoon 2020