In this tutorial, we are going to learn writing a python program to convert lowercase characters (alphabet) into uppercase characters (alphabet).
Problem Statement
For any input string, any lowercase character used in input string will be replaced with uppercase character of same alphabet as lowercase character.
For example:
Case1: if user inputs ‘Quescol’
The output should be ‘QUESCOL’
The ‘uescol’ of string is replaced with ‘UESCOL’
Case2: if user inputs ‘pyThon’
The output should be ‘PYTHON’
Our logic to convert lowercase character to uppercase character
- Our program will take a string input from the user.
- Then program will iterate through each character of the string.
- If any lowercase letter will found, then our program will convert it into uppercase letter using upper() function.
- And finally print the output.
Python code to convert lowercase character to uppercase character of string
string = input("Enter a String : ")
result=''
for i in string: #iterate through each letter/character from the string
if i.islower(): #if lowercase
i = i.upper() #converting lowercase into uppercase letter
result += i #concatenating each character of the string without lowercase letter
print("String after converting lowercase to upper :",result)
Output:
Enter a String : Quescol
String after converting lowercase to upper : QUESCOL
Explanation:
For the input string ‘Quescol’, all the lowercase letters i.e. ‘uescol’ is converted into respective uppercase i.e. ‘UESCOL’. While iterating through the string, the letters ‘u’, ‘e’, ‘s’, ‘c’, ‘o’, and ‘l’ return ‘True” as an output when is checked with ‘islower()’ function, then they are converted into respective uppercase letters using ‘isupper()’ function and replaced simultaneously.