728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | ✨✨✨✨✨#DICTIONARY programming_dictionary = { "Bug": "An error in a program that prevents the program from running as expected.", "Function": "A piece of code that you can easily call over and over again." } #Retrieving items from dictionary. print(programming_dictionary["Bug"]) #Adding new items to dictionary. programming_dictionary["Loop"] = "The action of doing something over and over again." print(programming_dictionary) #Create an empty dictionary. empty_dictionary = {} #엠티 딕셔너리를 만드는게 종종 편할 때도 있다. #Wipe a existing dictionary. programming_dictionary = {} #초기화 시켜버리는 것. print(programming_dictionary) #Edit an item in a dictionary. programming_dictionary["Bug"] = "A moth in your computer." #데피니션이 바뀜. #Loop through a dictionary. for key in programming_dictionary: print(key) print(programming_dictionary[key]) ✨✨✨✨✨#Grading using dictionary 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 add the grades to student_grades.👇 for name in student_scores: score = student_scores[name] if score > 90: student_grades[name] = "Outstanding" elif score > 80: student_grades[name] = "Exceeds Expectations" elif score > 70: student_grades[name] = "Acceptable" else: student_grades[name] = "Fail" # 🚨 Don't change the code below 👇 print(student_grades) ✨✨✨✨✨#Nesting capitals = { "France": "Paris", "Germany": "Berlin", } #딕셔너리 안에 리스트를 네스팅하기 travel_log = { "France": {"cities_visited": ["Paris", "Lillie", "Dijon"], "total_visits": 12}, "Germany": {"cities_visited": ["Munich", "Berlin"], "total_visits": 9}, } #리스트 안에 딕셔너리를 네스팅하기 travel_log = [ { "country": "France", "cities_visited": ["Paris", "Lillie", "Dijon"], "total_visits": 12 }, { "Country": "Germany", "cities_visited": ["Munich", "Berlin"], "total_visits": 9 }, ] ✨✨✨✨#Dictionary in 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_visited, times_visited, cities_visited): new_country = {} new_country["country"] = country_visited new_country["visits"] = times_visited new_country["cities"] = cities_visited travel_log.append(new_country) #🚨 Do not change the code below add_new_country("Russia", 2, ["Moscow", "Saint Petersburg"]) print(travel_log) ✨✨✨✨✨비밀경매 만들기 from replit import clear bids = {} bidding_finished = False def find_highest_bidder(bidding_record): #bidding_record = {"Angela": 123, "James": 321} highest_bid = 0 for bidder in bidding_record: bid_amount = bidding_record[bidder] if bid_amount > highest_bid: highest_bid = bid_amount winner = bidder print(f"The winner is {winner} with a bid of ${highest_bid}.") while not bidding_finished: name = input(f"What is your name? : ") price = int(input(f"What is your bid? : $")) bids[name] = price should_continue = input(f"Are there any other bidders? Y or N : ").lower() if should_continue == "n": bidding_finished = True find_highest_bidder(bids) elif should_continue == "y": clear() | cs |
'😯 사는 이야기 > 코린이 파이썬' 카테고리의 다른 글
Day 13 (100 Days of Code: Python) - Scope & Number guessing game (0) | 2022.06.11 |
---|---|
Day 10 (100 Days of Code: Python) - Functions with Outputs (0) | 2022.06.07 |
Day 08 (100 Days of Code: Python) - Function Parameters (0) | 2022.05.23 |
Day 07 (100 Days of Code: Python) -Hangman (0) | 2022.05.12 |
Day 06 (100 Days of Code: Python) - Functions & Karel (0) | 2022.05.09 |