In this program, we will take a word as input from the user and convert all uppercase to lowercase in a word.
Steps to solve the program
- Take a word as input from the user.
- Use for loop to iterate over each character of the word.
- Check whether the character is uppercase or not using isupper().
- If it is an uppercase character convert it to lowercase using lower().
- Print the output.
Solution 1 :
input1 = input("Enter word: ")
result = ''
for char in input1:
if char.isupper():
print(char.lower(),end="")
else:
print(char,end="")
Output :
Enter word: SQATOOLS
sqatools
Solution 2 :
str1 = input("Enter input string:")
result = ""
for char in str1:
# get character ascii value
char_ascii = ord(char)
# check ascii value between 65 - 90 range
# then character is in upper case
if 65 <= char_ascii <= 90:
# get character exact location
char_position = char_ascii - 65
# convert upper char ascii to lower case.
# add character to the result
result = result + chr(97+char_position)
else:
result = result + char
print("Result :", result)
Output
Enter Input String: SQATOOLS Learning
Result : sqatools learning