Answer:
Hi there Tonyhh! Please find the implementation below.
Explanation:
You can save the below code in a file called "price_discount.py". The code is implemented in python 2.0+. To make it work in Python 3.0+, simply update the code to use "input" rather than "raw_input".
price_discount.py
def calculate_discount(price, quantity):
total = 0.95 * price * quantity;
return total;
price = raw_input("Enter a price: ");
try:
price = int(price);
while price <= 0:
print("Input a valid number: ")
price = raw_input("Enter a price: ");
quantity = raw_input("Enter a quantity: ");
try:
quantity = int(quantity);
if quantity >= 10:
print(calculate_discount(price, quantity));
except ValueError:
print("Invalid quantity!")
except ValueError:
print("Invalid input!");
price = -1;