# 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

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))

# 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

# 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}")

# 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]

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))

# 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)

# 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])

# 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.")

# 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]

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(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))

Time to Complete: 20 minutes
Rating: Beginner

Code:

‘Create a list of in person sales transactions’

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

salesTransactions.append(7.35)

‘Display the sales transactions and the number of transactions’

print(salesTransactions)

print(len(salesTransactions))

‘Find the 5th sales transaction and provide a sales tax rate’

transactionAmount = salesTransactions[4]

salesTaxRate = .0745

‘Calculate the amount of sales tax’

salesTaxAmount = transactionAmount * salesTaxRate

‘Calculate the order total amount’

totalAmount = salesTaxAmount + transactionAmount

‘Round the order total to 2 decimal places’

totalAmount = round(totalAmount,2)

‘Display the order total’

print(totalAmount)

‘Find the minimum and maximum sales amounts’

minSales = min(salesTransactions)

maxSales = max(salesTransactions)

‘Calculate the difference between the minimum and maximum sales’

salesDiff = maxSales - minSales

‘Create a range of the lowest and highest sales amounts’

salesRange = range(int(minSales), int(maxSales))

‘Display the sales range’

print(salesRange)

1 Like

Time to complete: 12 minutes
Ranking: Beginner

Solution:

##### all transactions + total amount

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]

online_tran = 7.35

transactions.append(online_tran)

print(transactions, len(transactions))

##### total amount owed to customer for cake

retCake = transactions[4]

cakeTax = retCake * .0745

cakeTotal = retCake + cakeTax

roundCake = round(cakeTotal, 2)

print(roundCake)

##### highest and lowest sales and the difference

highSale = max(transactions)

lowSale = min(transactions)

dif = highSale - lowSale

print(dif)

##### range of sales

highSale = int(highSale)

lowSale = int(lowSale)

salesRange = range(lowSale, highSale)

print(salesRange)

#Total of 12 sales today at your location

sales_today = [10.50, 7.50, 9.25, 8.30, 7.50, 9.60, 8.45, 6.95, 7.25, 7.50, 11.75, 6.50]
online_sale = 7.35

print(“** Here are the sales today:”)
sales_today.append(online_sale)
print(sales_today)
print(“** How many items were sold today?”)
print(len(sales_today))

#Customer is asking to return the cake they bought

fifth_trans = sales_today[4]
print(“** What was the fifth transaction of the day?”)
print(fifth_trans)

fifth_cust_tax = 0.0745

sales_tax = (fifth_trans * fifth_cust_tax)
print(“** What was the sales tax of the transaction?”)
print(sales_tax)

tot_cost = (fifth_trans + sales_tax)
price_rounded = round(tot_cost, 2)
print(“** Amount owed back to customer is:”)
print(price_rounded)

max_price = max(sales_today)
min_price = min(sales_today)
diff_price = (max_price - min_price)
print(“** The difference in price is:”)
print(diff_price)

min_sale = int(min_price)
max_sale = int(max_price)

range_of_sales = range(min_sale, max_sale)
print(“** The range of sales is:”)
print(range_of_sales)

Time to complete: 8 minutes
Rating: Beginner

Solution:

#2)
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(“length =”, len(sales))

#3)
customer = sales[4]
tax = customer*0.0745
paid = customer + tax
print(“Amount owed back to customer: \$” + str(round(paid, 2)))

#4)
minimum = min(sales)
maximum = max(sales)
print(“Difference between minimum and maximum sales amounts: \$” + str(maximum - minimum))

#5)
salesRange = range(int(minimum), int(maximum)+1)
print(“Sales range:”, list(salesRange))

#2
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]
online_ts = 7.35
transactions.append(online_ts)

print(transactions)
print(len(transactions))

#3
fifth = transactions[4]
fifth_tax = fifth*0.0745
fifth_total = fifth + fifth_tax