- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count upper and lower case characters without using inbuilt functions in Python program
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a string, we need to count the number of uppercase and lowercase characters present in the string without using the inbuilt function
This can be easily solved by using islower() and isupper() function available in python. But here there is a constraint to use the inbuilt function. So here we take the help of the ASCII value of the characters.
Using the ord() function we compute the ASCII value of each character present in the string and then compare to check for uppercase and lowercase as shown below.
def upperlower(string): upper = 0 lower = 0 for i in range(len(string)): # For lowercase if (ord(string[i]) >= 97 and ord(string[i]) <= 122): lower += 1 # For uppercase elif (ord(string[i]) >= 65 and ord(string[i]) <= 90): upper += 1 print('Lower case characters = '+str(lower)) print('Upper case characters = '+str(upper)) # Driver Code string = 'TutorialsPoint' upperlower(string)
Lower case characters = 12 Upper case characters = 2
All the variables are declared in the local scope and their references are seen in the figure above.
In this article, we have learned how to count uppercase and lowercase characters present in the given string
- Python program to count upper and lower case characters without using inbuilt functions
- Java program to count upper and lower case characters in a given string
- C# program to count upper and lower case characters in a given string
- How to convert Lower case to Upper Case using C#?
- How to convert Upper case to Lower Case using C#?
- C program to convert upper case to lower and vice versa by using string concepts
- Convert vowels from upper to lower or lower to upper using C program
- MySQL Query to change lower case to upper case?
- How to return the first unique character without using inbuilt functions using C#?
- Python regex to find sequences of one upper case letter followed by lower case letters
- How to return the index of first unique character without inbuilt functions using C#?
- Program for converting Alternate characters of a string to Upper Case.\n
- isupper(), islower(), lower(), upper() in Python and their applications
- Java Program to check whether the entered character a digit, white space, lower case or upper case character