-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassgn4.3_ParsingString.py
More file actions
24 lines (18 loc) · 987 Bytes
/
Copy pathassgn4.3_ParsingString.py
File metadata and controls
24 lines (18 loc) · 987 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
#!/usr/bin/env python3
## Name of program: assgn4.3_ParsingString.py
## Fucntion: Reads a sentence/string from user and turns all letters to lowercase,
## removes spaces, counts and prints out the length of the string
## Author: Chandra Sarkar
### takes string input from user ###
sentence = str(input("Input a sentence: "))
### turn sentence into lowercase and print it ###
sentence_lowercase = sentence.lower()
print ("\nThe sentence in all lower case is:\t", sentence_lowercase)
### remove spaces ###
sentence_no_space = sentence.replace(" ","")
print ("\nThe sentence with no space:\t", sentence_no_space)
### counts no. of characters of the sentence and prints out ###
sentence_length = len(sentence) #length of sentence without spaces i.e. original input length
print ("\nThe length of the original sentence:\t",sentence_length)
sentence_length_nospace = len(sentence_no_space)
print ("\nThe length of the sentence without spaces:\t",sentence_length_nospace)