100일 간의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 9일차(비밀 경매)

10272 단어

연습 9.1 - 채점 프로그램




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)


연습 9.2 - 목록의 사전




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)


프로젝트 9 - 비밀 경매




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


참고 - 본인이 참조할 수 있도록 코드에 주석을 추가했습니다. 나는 실제로 프로그램을 작성하기 위해 다음 순서도를 작업했습니다.

좋은 웹페이지 즐겨찾기