-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7week.py
More file actions
148 lines (109 loc) · 3.36 KB
/
Copy path7week.py
File metadata and controls
148 lines (109 loc) · 3.36 KB
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
# 7주차 튜플
# 수업시간 끄적끄적
gen = (x * x for x in range(5))
"""
print(gen)
x = tuple(gen)
print(x)
y = list(gen)
print(y)
z=list(x)
print(z)
# Lab: 문자열의 공통 문자
x = input("첫 번쨰 문자열: ")
y = input("두 번째 문자열: ")
print(f"{set(x)&set(y)}")
# Lab: 문자열의 공통 문자
s = set(input("입력 텍스트: ").split())
print(f"사용된 단어의 개수 = {len(s)}")
print(s)
# Lab: 영한 사전
en_kr_dict = {"one": "하나", "two": "둘", "three": "셋"}
en_word = input("단어를 입력하시오: ")
print(en_kr_dict[en_word])
"""
# Lab: 연락처 처리
contacts = dict()
def print_menu():
print("1. 연락처 추가")
print("2. 연락처 삭제")
print("3. 연락처 검색")
print("4. 연락처 출력")
print("5. 종료")
while True:
print_menu()
menu = int(input("메뉴 항목을 선택하세요: "))
if menu == 1:
input_key_name = input("이름: ")
val_phone = input("전화번호: ")
contacts[input_key_name] = val_phone
elif menu == 2:
del_key_name = input("이름: ")
contacts.pop(del_key_name)
elif menu == 3:
find_key_name = input("이름: ")
if find_key_name in contacts:
print(f"{find_key_name}의 전화번호 : {contacts[find_key_name]}")
else:
print("해당 연락처가 없습니다.")
elif menu == 4:
for key_name in contacts:
print(f"{key_name}의 전화번호 : {contacts[key_name]}")
else:
print("해당 연락처가 없습니다.")
elif menu == 5:
break
else:
print("잘못입력하셨습니다.")
# Lab: 학생 성적 처리
score_dic = {
"Kim":[99,83,95],
"Lee":[68,45,78],
"Choi":[25,56,69]
}
for k, v in score_dic.items(): # k -> 학생이름, v-> 성적
print(f"{k}의 평균성적 = {sum(v)/len(v)}")
# Lab: 단어 카운터 만들기
text_data = "Create the highest, grandest vision possible for your life, because you become what you believe"
text_count = dict() # 공백 dict
for word in text_data.split():
word = word.strip(",")
if word in text_count:
text_count[word] += 1
else:
text_count[word] = 1
# text_count[word] = text_count.get(word, 0) + 1 -> 요것도 가능
# 가져왔을 때 처음에는 0으로 가져와서 1 더하고, 이후는 이전에 저장된 값에 +1을 하기
for k, v in text_count.items():
print(f"{k}의 등장횟수 = {v}")
# Lab: 회문 검사하기
palindrome = input("문자열을 입력하세요: ")
if palindrome == palindrome[::-1]:
print("회문입니다.")
else:
print("회문이 아닙니다.")
# Lab: 머리 글자어 만들기
acronym = input("문자열을 입력하시오: ")
word_CAP = acronym.split()
s = ""
for i in word_CAP:
s += i[0]
print(s)
# Lab: 이메일 주소 분석
e_mail = input("이메일 주소를 입력하시오: ")
id_domain = e_mail.split("@")
print(e_mail)
print(f"아이디: {id_domain[0]}")
print(f"도메인: {id_domain[1]}")
# Lab: 문자열 분석
cal = {"digits": 0, "spaces": 0, "alphas": 0}
analysis_str = input("문자열을 입력하시오: ")
for i in analysis_str:
if i.isdigit():
cal["digits"] += 1
elif i.isspace():
cal["spaces"] += 1
elif i.isalpha():
cal["alphas"] += 1
for k, v in cal.items():
print(f"{k}의 개수 : {v}")