-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_count.py
46 lines (39 loc) · 1.55 KB
/
strings_count.py
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
38
39
40
41
42
43
44
45
46
# Count strings in a sentence
# Count lower case and uppercases
# Converting of strings
sentence = 'To construct the notion of a Lie group in Dirac geometry, extending the definition of Poisson Lie groups, the Courant algebroids A must themselves carry a multiplicative structure.'
newstring = ' '
count_upperCase = 0
count_lowerCase = 0
count_blankspace = 0
#total length of sentence
totalLen = len(sentence)
#half length of sentence
halfString = totalLen/2
#for loops
for letter in sentence:
# Checking for lowercase letter and
# converting to uppercase.
if (letter.isupper()) == True:
count_upperCase+= 1
newstring+=(letter.lower())
# Checking for uppercase letter and
# converting to lowercase.
elif (letter.islower()) == True:
count_lowerCase+= 1
newstring+=(letter.upper())
# Checking for whitespace letter and
# adding it to the new string as it is.
elif (letter.isspace()) == True:
count_blankspace+= 1
newstring+= letter
totalChar = count_upperCase + count_lowerCase + count_blankspace
print("String: \n To construct the notion of a Lie group in Dirac geometry, extending the definition of Poisson Lie groups, the Courant algebroids A must themselves carry a multiplicative structure.")
print("\n Total Length - ", totalLen)
print("\n Total Characters Length - ", totalChar)
print("\n Uppercase - ", count_upperCase)
print("\n Lowercase - ", count_lowerCase)
print("\n Spaces -", count_blankspace)
print("\n Converted String:")
print(newstring)
print(halfString)