Python/개념정리
파이썬 [ 능력단위 평가 실습 ]
Itchild
2024. 5. 14. 16:38
728x90
반응형
✔️ 문제
- 정확한 입력시 그래프 출력
- 잘못된 입력 시 '해당 이름을 가진 동은 없습니다.' 출력
- 데이터 2개 이상 나올 시 '해당 이름을 가진 동이 여러개입니다!' 출력

✅ 슈도코딩
▪️ "역삼" 입력된 검색어가 들어가는 동 모두 출력
▪️ 몇번만에 성공 할지 모르니 while
▪️ 해당 동이 2개 이상이라면 " 해당동이 여러개 입니다!" 출력
▪️ 해당 동이 1개가 되도록 맞게 입력하였다면 "역삼1동" break
import csv
import matplotlib.pyplot as plt
import numpy as np
while True:
with open('korea.csv','r') as file:
data=csv.reader(file)
header=next(data)
print()
area=input('동 이름 입력>> ')
city=[]
for row in data:
if area in row[0]:
city.append(row[0])
sample=np.array(row[3:], dtype=int)
print(row[0])
if not city:
print('해당 이름을 가진 동은 없습니다.')
elif len(city) ==1:
break
else:
print('해당 이름을 가진 동이 여러개입니다!')
print('정확하게 입력해주세요!')
plt.plot(sample)
plt.show()
728x90
반응형