0% found this document useful (0 votes)
2 views3 pages

Python Lab 5

The document outlines a Python program to count the number of uppercase and lowercase letters in a given string. It includes explanations of string case manipulation methods like .upper(), .lower(), .isupper(), and .islower(), along with example code. The source code provided demonstrates how to read a string and calculate the counts of uppercase and lowercase letters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Lab 5

The document outlines a Python program to count the number of uppercase and lowercase letters in a given string. It includes explanations of string case manipulation methods like .upper(), .lower(), .isupper(), and .islower(), along with example code. The source code provided demonstrates how to read a string and calculate the counts of uppercase and lowercase letters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like