노승현
python - 문제풀이 본문
## 단어를 입력받습니다
## 사용자는 영어로만 입력합니다.
## 영단어 입력 >> apple
## 영단어 입력 >> banana
## 영단어 입력 >> candy
## 영단어 입력 >> angle
## 영단어 입력 >> ant
## stop 이 입렫되면 종료
## 입력한 영단어들 중에서 a로 시작하는 단어만 datas 리스트에 저장해서 출력해주세요
datas=[]
while True:
word= input('영단어를 입력해주세요 >> ')
if word =='stop':
break
elif word.startswith('a'):
datas.append(word)
print(datas)
startswith : 맨 앞에 있는 글자를 찾는 함수
2번 문제
## +) a가 가장많이 들어간 단어를 출력해주세요
##2개 이상이면 첫번째 단어만 출력해주세요
datas=[]
aword=''
while True:
word = input('영단어를 입력해주세요 >> ')
if word =='stop':
break
elif word.startswith('a'):
datas.append(word)
if aword.count('a') < word.count('a'):
aword=word
print(aword)
'Python' 카테고리의 다른 글
python - 데이터 가공 (0) | 2024.05.10 |
---|---|
python - 파일 입출력 (0) | 2024.05.08 |
UP & DOWN 게임 (python) (0) | 2024.05.03 |
python - 함수와 메서드 (1) | 2024.05.03 |
python - 함수 (0) | 2024.05.02 |