[Python] 입력된 문장 중에서 사용자가 지정한 위치의 단어만 출력하는 코드 작성

·2023년 4월 13일
0

[ Python ]

목록 보기
9/19

✅ 문장과 위치의 입력은 input() 사용

📄 연습 문제

input_sentence = str(input('enter sentence >>'))
word_list = input_sentence.split()
word_index = int(input('enter position >>'))

print(f'문장의 {word_index}번째 단어는 {word_list[word_index]}')

📝 실행 예시

enter sentence >> Python is a very easy language.
enter position >> 4

문장의 4번째 단어는 very
profile
https://dribbble.com/ohseyun

0개의 댓글