PROGRAM – 05
Objec ve:
Write a program to read a string and print the total number of upper
case and lower case le ers in it.
So ware/Tools Required:
Python installed from h ps://www.python.org
IDLE (Python's built-in IDE)
Theory:
In Python, uppercase and lowercase le ers play an important role in string
manipula on.
You can change the case of a string using .upper() and .lower(), and check
its case using .isupper() and .islower().
Here's how they work:
1. Changing Case :
.upper(): Converts all lowercase le ers in a string to uppercase.
.lower(): Converts all uppercase le ers in a string to lowercase.
Example:
text = "Hello World"
print(text.upper()) # Output: HELLO WORLD
print(text.lower()) # Output: hello world
2. Checking Case:
.isupper(): Returns True if all characters in the string are uppercase
(ignores non-le er characters).
.islower(): Returns True if all characters in the string are lowercase
(ignores non-le er characters).
Example:
word = "PYTHON"
print(word.isupper()) # Output = True
word2 = "python"
print(word2.islower()) # Output = True
word3 = "Python"
print(word3.isupper()) # Output = False
print(word3.islower()) # Output = False
Source code:
Thestring = input(“Enter your string here : ”)
Uppercase = 0
Lowercase = 0
for chr in Thestring :
if chr.isupper() :
Uppercase = Uppercase + 1
elif chr.islower() :
Lowercase = Lowercase + 1
print(“The number of upper case characters are : ” , Uppercase)
print(“The number of lower case characters are : ” , Lowercase)
Output :
Enter your string here : Hello my name is Sanskar Gupta
The number of upper case characters are : 3
The number of lower case characters are : 22