- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to count upper and lower case characters without using inbuilt functions
In this article, we will learn about the solution and approach to solve the given problem statement.
Given a string input, we need to find the number of uppercase & lowercase characters in the given strings.
Here we will we checking ASCII value of each character by the help of built-in ord() function.
Here we have assigned two counters to 0 and we are traversing the input string and checking their ASCII values and incrementing their counter respectively.
Now let’s see the implementation 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 = %s' %lower, 'Upper case characters = %s' %upper) # Driver Code string = 'Tutorialspoint' upperlower(string)
Lower case characters = 13 Upper case characters = 1
All variables and functions are declared in global scope as shown in the figure below.
In this article, we learned about the approach to count upper and lower case characters without using inbuilt functions.
- Count upper and lower case characters without using inbuilt functions in Python program
- Python 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
- Java 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#?
- MySQL Query to change lower case to upper case?
- Convert vowels from upper to lower or lower to upper using C program
- C program to convert upper case to lower and vice versa by using string concepts
- Python regex to find sequences of one upper case letter followed by lower case letters
- How to return the first unique character without using inbuilt functions using C#?
- Program for converting Alternate characters of a string to Upper Case.
- Java Program to check whether the entered character a digit, white space, lower case or upper case character
- isupper(), islower(), lower(), upper() in Python and their applications