165|PYTHON – LePan’s Big Day

BYU Student Author: @Millie_K_B
Reviewers: @Trent_Barlow, @Kyle_nilsen
Estimated Time to Solve: 20 Minutes

This is an intro challenge that is part of the Python Learning Path.

We provide the solution to this challenge using:

  • Python

Need a program? Click here.

Overview
After winning your local bake-off, you decide to ride the success and fame and open up your own French-inspired bakery, LePan Baked Goods.

On your big opening day, you sold six loaves of bread, three mini cakes, and four sets of dinner rolls. Some people added extra goodies to their order, like a cookie or a jar of jam. Others got discounted prices for coming in at the end of the day and purchasing goods considered “old.” All of this variety means that very few totals came out to the same price.

Now that your doors are closed, it’s time to take a look at your sales for the day.

Instructions

  1. Open up Visual Studio Code and create a new Jupyter notebook.
  2. You made a total of 12 sales today at your location. You do not record sales tax as part of these sales. The 12 transactions were as follows:
    • 10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50
    • Create a list in Python that stores all of these sales transactions.
    • You also had one online sale, for 7.35. Add this sale to the sales transaction list using .append().
    • Print this list so you can see all of the data.
    • Also print the length of the list using the len() function to confirm that everything was added correctly. The new length should be 13.
  3. A customer called asking to return the cake they bought. You remember that this customer was your fifth transaction of the day.
    • Determine which transaction belongs to this customer and assign that transaction to a new variable.
    • Compute the sales tax that the customer paid. Use a rate of 7.45%.
    • Find the total amount that the customer paid, which will be the sales tax amount plus the transaction amount.
    • Round this amount to two decimal places, using the round() function.
    • Print the amount owed back to the customer.
  4. You’re curious to see the difference between your highest and lowest sales amounts.
    • Find the minimum and maximum sales amounts using min() and max().
    • Calculate the difference between the maximum and maximum sales.
    • Print the difference.
  5. It is helpful to know the general range of transaction amounts so you can stock the correct change. For example, if transactions never go beyond $15, you won’t need to stock many $20 bills for change.
    • Using the maximum and minimum sales amounts, create a range of sales transactions.
    • Print the range.
Suggestions and Hints
  • When indexing a list, remember that Python starts “counting” at 0. For example, to find the third object in the list, you would index the list like this: list[2].
  • Remember that if you are altering a variable, you need to reassign the altered variable to the variable name so that the alteration “saves” to the variable name.
  • All of the sales transactions will be float data types. If you encounter an error with data types, use the int() function to change the transaction to an integer. This will lose some accuracy but will allow you to continue manipulating the data.

Solution

create a list of the sles

list_of_sales = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

create a variable

online_sale = 7.35

add the online_sale to the end of the list

list_of_sales.append(online_sale)
print(f"Sales Transactions List:\n{list_of_sales}")
print(len(list_of_sales))

A customer called asking to return the cake they bought. You remember that this customer was your fifth transaction of the day.

Determine which transaction belongs to this customer and assign that transaction to a new variable.

transaction = input("Enter the transaction number you want to find (1-12): ")
found_transaction = False
for i in range(len(list_of_sales)):
if int(transaction) == i + 1:
found_transaction = True
selected_transaction = list_of_sales[i]
print(selected_transaction)
break
if not found_transaction:
print(“Transaction not found.”)

Compute the sales tax that the customer

tax_rate = 7.45 / 100
sales_tax = selected_transaction * tax_rate
amount_owed = sales_tax + selected_transaction
rounded_amount = round(amount_owed, 2)
print(f"\nAmount Owed Back to Customer: ${rounded_amount}")

Determine the Max and Min amounts

minimum_sales = min(list_of_sales)
maximum_sales = max(list_of_sales)
difference = maximum_sales - minimum_sales

print(f"\nThe difference between the highest and lowest sales amount is: ${difference}")

It is helpful to know the general range of transaction amounts so you can stock the correct change. For example, if transactions never go beyond $15, you won’t need to stock many $20 bills for change.

Using the maximum and minimum sales amounts, create a range of sales transactions.

Print the range.

range_of_sales = range(int(minimum_sales), int(maximum_sales))
print(f"\nRange of Sales Transactions: {range_of_sales}")

#2. make the data list

sales = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

#add the online transaction

sales.append(7.35)

print(sales)

print(len(sales))

#find 5th transaction

customer_return = sales[4]

sales_tax_amt = customer_return * .0745

#find total amount the customer paid

amt_owed = sales_tax_amt + customer_return

#round the amount owed to two decimal places

amt_owed = round(amt_owed,2)

#print the total amount

print(amt_owed)

#find min,max

min_sale = min(sales)

max_sale = max(sales)

#calculate the difference

difference = max_sale - min_sale

#print the difference

print(difference)

#make them ints

min_sale = int(min_sale)

max_sale = int(max_sale)

#create a sales range

sales_range = range(min_sale, max_sale)

#print the sales range

print(sales_range)

#Sona Extra Credit TechHub

sales = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

sales.append(7.35)

print(sales)
print(len(sales))

a = sales[4]

saleTax = a * .0745

total = a + saleTax

round(total)

print(total)

diff = max(sales) - min(sales)

print (diff)

import jupyterlab

sales_transaction = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

Append online sale

sales_transaction.append(7.35)

Print sales and length

print(“Sales Transactions:”, sales_transaction)

print(“Total Transactions:”, len(sales_transaction))

Determine the transaction to return

fifth_transaction = sales_transaction[4]

Calculate the sales tax and total amount for the return

sales_tax_rate = 7.45 / 100

sales_tax_paid = fifth_transaction * sales_tax_rate

total_amount_paid = fifth_transaction + sales_tax_paid

amount_owed_back = round(total_amount_paid, 2)

Print the amount owed back to the customer

print(“Amount Owed Back:”, amount_owed_back)

Find the minimum and maximum sales amounts

min_sale = min(sales_transaction)

max_sale = max(sales_transaction)

Calculate and print the difference between the highest and lowest sales

sale_difference = max_sale - min_sale

print(“Difference between Highest and Lowest Sale:”, sale_difference)

Create and print the range of sales transactions

sales_range = range(int(min_sale), int(max_sale) + 1)

print(“Range of Sales Transactions:”, list(sales_range))

John Colton

Create a list in Python that stores all of these sales transactions

lSales = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

You also had one online sale, for 7.35. Add this sale to the sales transaction list using .append().

lSales.append(7.35)

Print this list so you can see all of the data.

Also print the length of the list using the len() function to confirm that everything was added correctly. The new length should be 13.

for iCount in range(0,len(lSales)):

print(f"${lSales[iCount]}")

print(f"{len(lSales)} total sales.")

Determine which transaction belongs to this customer and assign that transaction to a new variable.

fReturn = float(lSales[4])

Compute the sales tax that the customer paid. Use a rate of 7.45%.

Find the total amount that the customer paid, which will be the sales tax amount plus the transaction amount.

fSalesTax = fReturn * 1.0745

fReturnTotal = fReturn + fSalesTax

#Round this amount to two decimal places, using the round() function.

#Print the amount owed back to the customer.

print(f"${round(fReturnTotal, 2)} owed back to the customer.")

Find the minimum and maximum sales amounts using min() and max().

fMinSale = float(min(lSales))

fMaxSale = float(max(lSales))

Calculate the difference between the maximum and maximum sales.

fMinMaxDiff = fMaxSale - fMinSale

Print the difference.

print(f"${float(fMinMaxDiff)} difference between the smallest and biggest sale.")

Using the maximum and minimum sales amounts, create a range of sales transactions.

Print the range.

print(f"Minimum Sale: ${fMinSale} Maximum Sale: ${fMaxSale}")

transactions = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

transactions.append(7.35)

print(transactions)

print(len(transactions))

customer_five = transactions[4]

sales_tax = customer_five * .0745

total = round(sales_tax + customer_five,2)

print(total)

min_sale = min(transactions)

max_sale = max(transactions)

difference = max_sale - min_sale

print(difference)

sales_range = range(int(max_sale), int(min_sale))

print(sales_range)

sales = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]

Add the online transaction

sales.append(7.35)

print(sales)
print(len(sales))

Find 5th transaction

customer_return = sales[4]

sales_tax_amt = customer_return * 0.0745

Find total amount the customer paid

amt_owed = sales_tax_amt + customer_return

Round the amount owed to two decimal places

amt_owed = round(amt_owed, 2)

Print the total amount

print(amt_owed)

Find min, max

min_sale = min(sales)
max_sale = max(sales)

Calculate the difference

difference = max_sale - min_sale

Print the difference

print(difference)

Make them ints

min_sale = int(min_sale)
max_sale = int(max_sale)

Create a sales range

sales_range = range(min_sale, max_sale + 1)

Print the sales range

print(list(sales_range))