def count_words(text):
words = text.split()
return len(words)
def count_sentences(text):
sentence_end = ['.', '!', '?']
count = 0
for char in text:
if char in sentence_end:
count += 1
return count
def most_common_letter(text):
text = text.lower()
common_letter = {}
for char in text:
if char.isalpha():
if char in common_letter:
common_letter[char] += 1
else:
common_letter[char] = 1
max_count = max(common_letter.values())
most_common = [char for char, count in common_letter.items() if count == max_count]
return most_common
def average_word_length(text):
clean_text = ''.join(char for char in text if char.isalnum() or char.isspace())
words = clean_text.split()
total_length = sum(len(word) for word in words)
return round(total_length / len(words), 2)
text = input("텍스트를 입력하세요:")
print("텍스트 분석결과!!")
print("단어 수:",count_words(text))
print("문장 수:",count_sentences(text))
print("가장 많이 사용된 알파벳:",most_common_letter(text))
print("평균 단어 길이:",average_word_length(text))
#"Hello! Welcome to the world of Python. Are you ready to explore?"
#가장 많이 사용된 알파벳이 동률이면 이에 해당하는 알파벳을 모두 출력
#특수문자는 제외하고 계산한다
#소수점 둘째자리까지