JINIers
Day 9 본문
아니 왜케..
머리가 돌이 된 것같지..
# Dictionary
list와 약간 다름
dictionary는 키가 식별하는 요소가 있음
형식
{"key" : value}
# {"key": value}
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.",
"Loop": "The action of doing something over and over again."
}
list[0] & dictionary 차이점
사전은 키가 식별하는 요소가 있음
# retrieving items from dictionary.
print(programming_dictionary["Bug"])
문제 : 올바른 function을 사용하지 않음
ㄴ 데이터 형식에서 키를 제공하도록 해야함
Loop: "The action of doing something over and over again."
ㄴ KeyError: 'Loop'
9 : "seveteen members 9th."
print(programming_dictionary[9]) → 출력됨
# adding new items to dictionary.
programming_dictionary["svt"] = "seventeen is k-pop idol."
# create an empty dictionary
empty_dictionary = {}
empty_dictionary = [] # add function
# wipe an existion dictionary
programming_dictionary = {}
print(programming_dictionary)
# edit an iten 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 Program
# 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 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"
elif score < 70:
student_grades[student] = "Fail"
'공부 > Python' 카테고리의 다른 글
Day 8 cipher (1) | 2024.06.17 |
---|---|
Day 8 def (0) | 2024.06.17 |
[Python 100 day challenge ] Day 6 - 허들 (1) | 2024.04.20 |
[Python 100 day challenge ] Day 5 - for (0) | 2024.03.27 |
[Python 100 day challenge ] Day 4 (0) | 2024.03.27 |
Comments