BANA3020 Lab5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Lab Practice 5: Conditionals and Flow

Control
BANA3020 Introduction to Programming with Python November 7, 2023

Lab Practice Submission Instructions:


• This is an individual lab practice and will typically be assigned in the laboratory (computer lab). You can
use your personal computer but all quizzes and practical exams will be performed with a lab computer.
• Your program should work correctly on all inputs. If there are any specifications about how the program
should be written (or how the output should appear), those specifications should be followed.
• Your code and functions/modules should be appropriately commented. However, try to avoid making
your code overly busy (e.g., include a comment on every line).
• Variables and functions should have meaningful names, and code should be organized into function-
s/methods where appropriate.
• Academic honesty is required in all work you submit to be graded. You should NOT copy or share your
code with other students to avoid plagiarism issues.
• Use the template provided to prepare your solutions.
• You should upload your .py file(s) to the Canvas before the end of the day.
• Submit separate .py file for each Lab problem with the following naming format: Lab5_Q1.py. Note: If
you are working on Jupyter Notebook, you need to download/convert it to Python .py file for submission.
• Late submission of lab practice without an approved extension will incur the following penalties:

(a) No submission by the deadline will incur 0.25 point deduction for each problem (most of the
problems are due at the end of the lab session).

(b) The instructor will deduct an additional 0.25 point per problem for each day past the deadline.

(c) The penalty will be deducted until the maximum possible score for the lab practice reaches zero
(0%) unless otherwise specified by the instructor.

Lab Practice 3 Page 1


Problem 1 - Business Profit or Loss Calculation
Create a Python program that helps a business determine whether they made a profit or a loss and calculate
the profit or loss amount. Ask the user for the following inputs:

• Total revenue generated by the business.

• Total expenses incurred by the business.

Then, use if-else statements to determine and print:

• If the revenue is greater than the expenses, print "The business made a profit of $X" (where X is the
profit amount).

• If expenses are greater than or equal to revenue, print "The business incurred a loss of $Y" (where Y is
the loss amount).

Example test case


1 Total revenue generated by the business : 5000
2 Total expenses incurred by the business : 3000
3 The business made a profit of $2000 .0
4

5 Total revenue generated by the business : 5000


6 Total expenses incurred by the business : 7000
7 The business incurred a loss of $2000 .0

Problem 2 - Customer Discount Calculation


Create a Python program that ask the user for the final price and calculates the final price for a customer’s
purchase based on the following conditions:

• If the purchase amount is less than $100, there is no discount.

• If the purchase amount is between $100 and $500, apply a 10% discount.

• If the purchase amount is greater than or equal to $500, apply a 20% discount.

Example test case


Test Case 1: No Discount for Less Than $100 Purchase

1 Purchase amount : 75
2 Expected result : There is no discount , your final price is $75 .0.

Test Case 2: 10% Discount for Purchase Between $100 and $500

1 Purchase amount : 150


2 Expected result : 10% discount , your final price is $135 .0.

Test Case 3: 10% Discount for Purchase Equal to $100

Lab Practice 3 Page 2


1 Purchase amount : 100
2 Expected result : 10% discount , your final price is $90 .0.

Test Case 4: 20% Discount for Purchase Over $500

1 Purchase amount : 700


2 Expected result : 20% discount , your final price is $560 .0.

Test Case 5: 20% Discount for Purchase Equal to $500

1 Purchase amount : 500


2 Expected result : 20% discount , your final price is $400 .0.

Problem 3 - Employee Salary Determination


Write a Python program that determines an employee’s salary based on the following criteria:

• Ask the user for their base salary.

• Ask the user for the number of years of experience the employee has.

Then, use multiple if statements to calculate the salary with the following conditions:

Years of Experience Bonus Percentage


Less than 1 5%
1 to 3 (inclusive) 7%
3 to 5 (inclusive) 10%
5 to 10 (inclusive) 15%
Greater than 10 20%

Calculate and print the final salary of the employee, including the bonus.

Example test case


Test Case 1: Employee with Less Than 1 Year of Experience

1 Base salary : 50000


2 Years of experience : 0.5
3 Expected final salary : $52500 .0 (5% bonus on the base salary )

Test Case 2: Employee with 2 Years of Experience

1 Base salary : 60000


2 Years of experience : 2
3 Expected final salary : $64200 .0 (7% bonus on the base salary )

Test Case 3: Employee with 4 Years of Experience

1 Base salary : 70000


2 Years of experience : 4
3 Expected final salary : $77000 .0 (10% bonus on the base salary )

Lab Practice 3 Page 3


Test Case 4: Employee with 6 Years of Experience

1 Base salary : 80000


2 Years of experience : 6
3 Expected final salary : $92000 .0 (15% bonus on the base salary )

Test Case 5: Employee with 12 Years of Experience

1 Base salary : 90000


2 Years of experience : 12
3 Expected final salary : $108000 .0 (20% bonus on the base salary )

Problem 4 - Loan Approval System


Create a Python program that simulates a loan approval system for a bank. The program should ask for the
applicant’s credit score and annual income. Use the following conditions to determine loan approval:

• If the credit score is above 700 and the annual income is greater than $50,000, approve the loan.

• If the credit score is between 600 and 700 (inclusive) and the annual income is greater than $60,000,
approve the loan.

• If the credit score is below 600 or the annual income is less than $40,000, deny the loan.

• For other cases, the decision should be "Under review."

Test Case 1: Approved Loan

1 Credit Score : 720


2 Annual Income : 55000
3 Loan approved

Test Case 2: Approved Loan

1 Credit Score : 650


2 Annual Income : 65000
3 Loan approved

Test Case 3: Denied Loan

1 Credit Score : 580


2 Annual Income : 35000
3 Loan denied

Test Case 4: Under Review

1 Credit Score : 680


2 Annual Income : 45000
3 Loan under review

Test Case 5: Under Review

Lab Practice 3 Page 4


1 Credit Score : 720
2 Annual Income : 48000
3 Loan under review

Lab Practice 3 Page 5

You might also like