-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10th.py
More file actions
48 lines (43 loc) · 1.44 KB
/
10th.py
File metadata and controls
48 lines (43 loc) · 1.44 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
# 학번: 2022189005
# 이름: 이경환
# 이메일: xerenes@yonsei.ac.kr
# 제출일: 2022-11-04
# 과제번호: 10주차 1번
print('어떤 노래를 선택할까요?\n "새삥", "After LIKE", "Hype Boy", "강남스타일"')
song = input("입력: ")
song = song.lower()
if song == "새삥":
with open("새삥.txt", "r", encoding="utf-8") as newthx:
txt = newthx.readlines()
elif song == "after like":
with open("After Like.txt", "r", encoding="utf-8") as al:
txt = al.readlines()
elif song == "hype boy":
with open("Hype Boy.txt", "r", encoding="utf-8") as Hb:
txt = Hb.readlines()
elif song == "강남스타일":
with open("강남스타일.txt", "r", encoding="utf-8") as gangnam:
txt = gangnam.readlines()
else:
raise Exception(f"{song}(이)라는 노래는 목록에 없습니다.")
li = []
con = []
for line in txt:
li.append(line.strip('\n'))
for words in li:
con.extend(words.split(" "))
while True:
word = input("가사에서 어떤 단어를 찾고 싶으신가요? : ")
if word == "":
print("단어 개수 찾기 프로그램을 종료합니다.")
break
cnt = 0
for words in con:
if word in words:
cnt += 1
else:
continue
if cnt > 0:
print(f'노래 "{song}"에서 "{word}"라는 가사는 {cnt}번 등장합니다.')
else:
print('가사가 없습니다')