Insert space before every capital letter

In this program, we will take a string as input and insert space before every capital letter appears in a given word.

Steps to solve the program
  1. Take a string as input and create an empty string.
  2. Use for loop to iterate over every character of the string.
  3. Add each character to the empty string.
  4. If a character is Capital letter then add space first then the character.
  5. Print the output.
				
					#Input string
str1 = "SqaTools pyThon"
result = ""

for char in str1:
    if char.isupper():
        result=result+" "+char
    else:
        result=result+char

#Printing output        
print(result)
				
			

Output :

				
					Sqa Tools py Thon
				
			

count the number of leap years within the range of years

uppercase half string

Leave a Comment