-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathCounts letters
More file actions
29 lines (24 loc) · 744 Bytes
/
Counts letters
File metadata and controls
29 lines (24 loc) · 744 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
def count_characters(input_string):
upper_count = 0
lower_count = 0
digit_count = 0
space_count = 0
for char in input_string:
if char.isupper():
upper_count += 1
elif char.islower():
lower_count += 1
elif char.isdigit():
digit_count += 1
elif char.isspace():
space_count += 1
return upper_count, lower_count, digit_count, space_count
def main():
user_input = input("Enter a string: ")
upper, lower, digits, spaces = count_characters(user_input)
print(f"Uppercase letters: {upper}")
print(f"Lowercase letters: {lower}")
print(f"Digits: {digits}")
print(f"Spaces: {spaces}")
if __name__ == "__main__":
main()