You will revise the programming concepts and knowledge you learned last year by creating a program using functions.
Open the following link for the first task - answer the questions.
open this link for task 2 - write a program (silent auction). You may use the Egg Order code to help you if with structure.
a copy of a possible coded answer will be here by Friday for week 3 for you to check your answer against.
You will have 3 days to complete the tasks (end of week 3), always ask if you are having issues with this. I can do this as a class task if it becomes apparent that too many of you are confused.
#Hannah Millward
#10.2.22
#Silent Auction
#Version 1
def check_number(message, lower_boundary):
while True:
try:
user_input = float(input(message))
if user_input > lower_boundary:
return user_input
else:
print(f"Number must be larger than {lower_boundary}.")
except ValueError:
print("Please input a valid integer.")
def get_reserve():
reserve = check_number("Enter reserve price $: ", 0)
return reserve
def get_bids():
bidder_name=""
while bidder_name!="Q":
bidder_name=input("Enter name or 'Q' to quit: ").title()
if bidder_name!="Q":
new_bid = check_number("Enter bid $:",0)
if new_bid > bid_list[-1]:
bidder_list.append(bidder_name)
bid_list.append(new_bid)
print(f"{bidder_name} has bid ${new_bid}.")
else:
print("You must bid higher than the previous bid.")
print(f"Last bid: {bidder_list[-1]} bid ${bid_list[-1]}.")
return bidder_list, bid_list
def print_summary(reserve, bidder_list, bid_list):
if bid_list[-1] >= reserve:
print(f"{bidder_list[-1]} has won the auction with a bid of ${bid_list[-1]:.2f}")
else:
print("\n*** Auction did not meet reserve price ***")
print("\nAuction history: ")
for i in range(1,len(bidder_list)):
print(f"{bidder_list[i]}: ${bid_list[i]}")
#main
bidder_list = [""]
bid_list = [0]
reserve = get_reserve()
bidder_list, bid_list = get_bids()
print_summary(reserve, bidder_list, bid_list)