In this example we will show how to count the number of uppercase and lowercase characters in a string.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
str = input("Input string:")
countLower = 0
countUpper = 0
for i in str:
if i.islower():
countLower += 1
elif i.isupper():
countUpper += 1
print("The number of lowercase characters in the string:", countLower)
print("The number of uppercase characters in the string:", countUpper)
Output:
Input string:Hello World
The number of lowercase characters in the string: 8
The number of uppercase characters in the string: 2