I've created this function to trim spaces in between words in string to run over them and get upper and lower case letters count.
The trouble is that "replace" method doesn't change the string and all spaces are counted as lowercase letters. I couldn't figure out why, so I wrote If statement to pass every time if i == " "
( which I actually didn't like), Is there any idea what I've done wrong?
My code:
testString = "Upper and Lower Case CALCULATION"
def case_counter(string, upperCount = 0, lowerCount = 0):
for i in string:
string.replace(" ", "")
if i.isupper():
upperCount += 1
else:
lowerCount += 1
print("Upper Letters count: ", upperCount)
print("Lower Letters count: ", lowerCount)
case_counter(testString)
print("\n")
My output:
Upper Letters count: 14
Lower Letters count: 18