티스토리 뷰
[파이썬] 연습문제. 1
# 1. 단어가 줄 단위로 저장된 words.txt 파일이 주어집니다.
# 다음 소스 코드를 완성하여 10자 이하인 단어의 개수가 출력되게 만드세요.
word.txt
anonymously
compatibility
dashboard
experience
photography
spotlight
warehouse
inFp = open("words.txt", "r")
inList = inFp.readlines()
count = 0
for i in inList:
test = str(i).rstrip()
if(len(test)<=10):
print(test, end="")
count+=1
print("10자 이하인 단어의 개수 : %d" % count)
# 2. 표준 입력으로 정수와 문자열이 각 줄에 입력됩니다.
# 다음 소스 코드를 완성하여 입력된 숫자에 해당하는 단어 단위 N-gram을 출력하세요.
# 만약 입력된 문자열의 단어 개수가 입력된 정수 미만이라면 'wrong'을 출력하세요.
#
# 실행 결과
# 7 (입력)
# Python is a programming language that lets you work quickly (입력)
# Python is a programming language that lets
# is a programming language that lets you
# a programming language that lets you work
# programming language that lets you work quickly
a = int(input("정수 입력 : "))
b = input("문자열 입력 : ")
words = b.split() # 문자열의 공백을 기준으로 리스트를 만들어주는 함수
print(words)
if(len(words)<a):
print("wrong")
else:
for i in range(len(words)-(a-1)):
for j in range(i, a+i):
print(words[j], end=' ') # 엔터없이 출력하기 위해 end = ' ' 사용
print()
'프로그래밍' 카테고리의 다른 글
[파이썬] 딕셔너리 (1) | 2018.08.13 |
---|---|
[안드로이드 스튜디오] Failed to find style 'coordinatorLayoutStyle' in current theme (0) | 2018.08.03 |
[Android] 안드로이드 네이버 검색 API 연동하기 (2) | 2018.07.27 |
[파이썬] 문자열 구성 파악 (0) | 2018.07.26 |
[JAVA] 별찍기 예제(직각삼각형, 피라미드형) (0) | 2018.07.26 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 오라클 null값 집계함수
- 파이썬기초
- 파이썬
- JavaFX
- 오라클 null값
- 오라클 집계함수
- WWW
- 자바글자수세기
- 딕셔너리
- 웹이란
- 파이썬 딕셔너리
- 글자수세기프로그램
- 아우터조인이란
- 아우터조인
- 자바
- Python dictionary
- 웹
- outer join
- 별찍기예제
- world wide web
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함