-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword_count.py
More file actions
37 lines (31 loc) · 972 Bytes
/
word_count.py
File metadata and controls
37 lines (31 loc) · 972 Bytes
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
31
32
33
34
35
36
37
import os
import sys
def count(text):
words = text.split()
num_words = len(words)
num_chars = len(text)
return num_words, num_chars
def get_user_input():
user_input = input("Enter text: ")
num_words, num_chars = count(user_input)
print("\nTotal word(s):", num_words)
print("Total character(s):", num_chars)
def main():
os.system('cls' if os.name == 'nt' else 'clear')
app_name = 'Count Words & Characters'
print(f'{"-" * 48}')
print(f'{" " * 12}{app_name}{" " * 12}')
print(f'{"-" * 48}')
get_user_input()
while True:
response = input('\nDo you want to continue? (Y/N) ')
if response == 'y' or response == 'Y':
main()
elif response == 'n' or response == 'N':
print('\nThank you and have a great day.\n')
sys.exit()
else:
print('\nError: Please select y or n.\n')
continue
if __name__ == '__main__':
main()