Calculate the length of a string with loop logic

In this program, we will take a string as input and calculate the length of a string with loop logic

Steps to solve the proram
  1. Take a string as input and create a variable and assign its value equal to zero.
  2. Use For loop to iterate over each character of the string.
  3. After each iteration add 1 to the variable to find the length of the string.
  4. To verify our solution find the length of the string using built it function len().
  5. Print the output.
				
					#Input string
string = "im am learing python"
count = 0

for char in string:
    count +=1
    
#Printing output
print("Length of the string using loop logic: ", count)
print("Length of the string using len(): ", len(string))
				
			

Output :

				
					Length of the string using loop logic:  20
Length of the string using len():  20
				
			

most simultaneously repeated characters in the input string.

replace the second occurrence of any char with the special character $.

Leave a Comment