DEV Community

Mike Kameta
Mike Kameta

Posted on • Updated on

100 Days of Code: The Complete Python Pro Bootcamp for 2022 - Day 9 (Secret Auction)

Exercise 9.1 - Grading Program

student_scores = {
  "Harry": 81,
  "Ron": 78,
  "Hermione": 99, 
  "Draco": 74,
  "Neville": 62,
}
#Don't change the code above 👆

#TODO-1: Create an empty dictionary called student_grades.
student_grades = {}

#TODO-2: Write your code below to covert scores into grades.👇
for student in student_scores:
    score = student_scores[student]
    if score > 90:
        student_grades[student] = "Outstanding"
    elif score > 80:
        student_grades[student] = "Exceeds Expectations"
    elif score > 70:
        student_grades[student] = "Acceptable"
    else:
        student_grades[student] = "Fail"


#Don't change the code below 👇
print(student_grades)
Enter fullscreen mode Exit fullscreen mode

Exercise 9.2 - Dictionary in a list

travel_log = [
{
  "country": "France",
  "visits": 12,
  "cities": ["Paris", "Lille", "Dijon"]
},
{
  "country": "Germany",
  "visits": 5,
  "cities": ["Berlin", "Hamburg", "Stuttgart"]
},
]
#🚨 Do NOT change the code above

#TODO: Write the function that will allow new countries
#to be added to the travel_log. 👇

def add_new_country(country_name, times_visited, cities_name,):
    new_country = {}
    new_country["country"] = country_name
    new_country["visits"] = times_visited
    new_country["cities"] = cities_name
    travel_log.append(new_country)



#🚨 Do not change the code below
add_new_country("Russia", 2, ["Moscow", "Saint Petersburg"])
print(travel_log)
Enter fullscreen mode Exit fullscreen mode

Project 9 - Secret Auction

from replit import clear
#HINT: You can call clear() to clear the output in the console.
#Import Logo, Print Logo and Print Welcome
from art import logo

print(logo)
print("Welcome to the silent auction program")

#Create variable
bidding_finished = False

#Create empty dictionary
auction_dictionary = {}

#Define function highest bid with print output
def find_highest_bid(auction_dictionary):
  highest_bid = 0
  for bidder in auction_dictionary:
    bid_amount = auction_dictionary[bidder]
    if bid_amount > highest_bid:
      highest_bid = bid_amount
      winner = bidder
  print(f"The winner is {winner} with the highest bid of ${highest_bid}.")

#Define while statement for inputs etc
while not bidding_finished:
  name = input("What is your name?: ")
  bid_amount = int(input("What is your bid? $" ))
  auction_dictionary[name] = bid_amount
  other_bids = input("Are there any other auctioneers?: Type 'yes' or 'no': ")
  if other_bids == 'no':
    bidding_finished = True
    find_highest_bid(auction_dictionary)
  elif other_bids == 'yes':
    clear()
Enter fullscreen mode Exit fullscreen mode

Note - I added comments to the code for my own reference. I actually worked off the following flow chart to write the programme:

Image description

Top comments (0)