In relation to this question, an upcoming exam (on the 20th May 2019) requires me to carry out this task using Visual Basic, Python or Pascal/Delphi. I am using Python (version 2.7/3.7) since the program is easier to read and write in this language. Here is the pre-release for my exam:
An auction company has an interactive auction board at their salerooms, which allows buyers to place bids at any time during the auction. Before the auction starts, the sellers place their items in the saleroom with a unique number attached to each item (item number). The following details about each item need to be set up on the interactive auction board system: the item number, number of bids, description, and reserve price. The number of bids is initially set to zero.
During the auction, buyers can look at the items in the saleroom and then place a bid on the interactive auction board at the saleroom. Each buyer is given a unique number for identification (buyer number). All the buyer needs to do is enter their buyer number, the item number, and their bid. Their bid must be greater than any existing bids.
At the end of the auction, the company checks all the items and marks those that have bids greater than the reserve as sold. Any items sold will incur a fee of 10% of the final bid to be paid to the auction company.
Write and test a program or programs for the auction company.
• Your program or programs must include appropriate prompts for the entry of data, data must be validated on entry.
• Error messages and other output need to be set out clearly and understandably.
• All variables, constants, and other identifiers must have meaningful names.
You will need to complete these three tasks. Each task must be fully tested.
Task 1 – Auction set up.
For every item in the auction the item number, description, and the reserve price should be recorded. The number of bids is set to zero. There must be at least 10 items in the auction.
Task 2 – Buyer bids.
A buyer should be able to find an item and view the item number, description, and the current highest bid. A buyer can then enter their buyer number and bid, which must be higher than any previously recorded bids. Every time a new bid is recorded the number of bids for that item is increased by one. Buyers can bid for an item many times and they can bid for many items.
Task 3 – At the end of the auction.
Using the results from TASK 2, identify items that have reached their reserve price, mark them as sold, calculate 10% of the final bid as the auction company fee and add this to the total fee for all sold items. Display this total fee. Display the item number and final bid for all the items with bids that have not reached their reserve price. Display the item number of any items that have received no bids. Display the number of items sold, the number of items that did not meet the reserve price and the number of items with no bids.
Here is my solution (program) to the question, task by task:
number_of_bids = 0 count = 0 auction_fee = 0.0 item_no = 0 sold_items = 0 less_than_reserve = 0 zero_bids_items = 0 min_items = 10 while True: try: n = int(input("Enter the number of items in the auction: ")) if n < min_items: raise ValueError except ValueError: print ("Number of items have to be at least 10!") else: current_highest_bid = [0.0]*n item_bids = *n item_description = *n reserve_price = *n item_numbers = *n buyer_no_Array = *n break #TASK 1 for i in range(n): item_no = item_no + 1 item_numbers.append(item_no) print ("ENTER DETAILS FOR ITEM NO.", item_no) description = input("Enter description for item no. " + str(item_no)) item_description.append(description) reserve = float(input("Enter reserve price for item no. " + str(item_no))) reserve_price.append(reserve) #TASK 2 while count != "y": for i in range(n): print ("Item number:", item_numbers[i], "Description:", item_description[i], "Reserve price:", reserve_price[i], end = " ") print ("Current highest bid:", current_highest_bid[i], "No. of bids:", item_bids[i], end = " ") print ("Buyer with highest bid:", buyer_no_Array[i]) choice = input("Do you want to bid for items in this auction? (y/n): ") if (choice == "y"): buyer_no = int(input("Enter your buyer ID: ")) item_choice = int(input("Enter the item number for your choice of item: ")) if item_choice in item_numbers: index = item_numbers.index(item_choice) while True: try: bid_price = float(input("Please enter your bid: ")) if (bid_price <= current_highest_bid[index]): raise ValueError except ValueError: print ("Bid should be higher than the current highest bid!") else: current_highest_bid[index] = bid_price number_of_bids = int(item_bids[index]) + 1 item_bids[index] = number_of_bids print ("Bids for", item_description[index], "are:", item_bids[index]) buyer_no_Array[index] = buyer_no break else: print ("Invalid item code!") elif (choice == "n"): count = input("END THE AUCTION? Enter 'n' to continue bidding or 'y' to end the auction: ") #TASK 3 if (count == "y"): sold = False for i in range(len(current_highest_bid)): if (current_highest_bid[i] >= reserve_price[i]): sold = True sold_items = sold_items + 1 auction_fee = auction_fee + (current_highest_bid[i] * 0.1) print ("The total auction company fee is: $", auction_fee) for i in range(len(current_highest_bid)): if (current_highest_bid[i] < reserve_price[i]): less_than_reserve = less_than_reserve + 1 print ("Item code", item_numbers[i], "with final bid $", current_highest_bid[i], "has not reached the reserve price.") for i in range(len(current_highest_bid)): if (current_highest_bid[i] == 0): zero_bids_items = zero_bids_items + 1 print ("Item code", item_numbers[i], "has not received any bids.") print ("Number of items sold are:", sold_items) print ("Number of items that did not meet the reserve price are:" , less_than_reserve) print ("Number of items with no bids are:", zero_bids_items) else: print ("Invalid input!")
NOTE: I would recommend you to test the program by using a smaller value of
min_items so that it is easier to test the program.
So, I would like to know whether I could make this code shorter and more efficient (to achieve the best marks), as my exam board focuses more on the efficiency of a program.