-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.18 Ch 6 Warm up Text analyzer & modifier Python 3.py
More file actions
30 lines (23 loc) · 1.29 KB
/
Copy path6.18 Ch 6 Warm up Text analyzer & modifier Python 3.py
File metadata and controls
30 lines (23 loc) · 1.29 KB
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
# (2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string.
# We encourage you to use a for loop in this function. (2 pts)
# (3) Extend the program by calling the get_num_of_characters() function and then output the returned result. (1 pt)
def get_num_of_characters(inputStr):
num_of_characters = 0
for character in inputStr:
num_of_characters = num_of_characters + 1
return num_of_characters
# (4) Extend the program further by implementing the output_without_whitespace() function. output_without_whitespace() outputs the
# string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the output_without_whitespace() function in main(). (2 pts)
def output_without_whitespace(input):
no_space_input = ''
for a in input:
if a != ' ':
no_space_input = no_space_input + a
return no_space_input
if __name__ == '__main__':
#(1) Prompt the user to enter a string of their choosing. Output the string. (1 pt)
print('Enter a sentence or phrase:')
user_unput1 = input()
print('You entered: ' + user_unput1)
print('Number of characters: ' + str(get_num_of_characters(user_unput1)))
print('String with no whitespace: ' + str(output_without_whitespace(user_unput1)))