# Number of characters in a string python

20 views

## Problem:

How are you doing guys? I am trying to write a python program to find chars in a string. I’ve done something lame that's why my loop is running infinity in the program. Could you please write me a code where I can find all the characters count in a string? I know it’s a bit offensive to ask raw code but I have no other options left. I tried a lot of times and googled over an hour. No possible solution I got so far.

## Solution:

It is important to find and understand the algorithm of a problem before start writing the codes. You need to realize that programming is not such a thing that can not be learned by heart. You need to be logical first and pull out the algorithm before anything else. Let’s write the algorithm for this particular problem and then we’ll write the codes.

#  Prompt the user to enter the string and then read it, and store it in a variable.

# Initialize a counter variable and assign zero to it. We will increment the value by 1 every time if we found any character in the given string.

# We will use a loop and iterate over the string.

# Check for each character If we get a blank character or not. If it is not a blank character, increment the value of the counter variable by 1.

# After completing the iteration, we’ll print the value of the counter. Hence this variable is holding our total number of characters.

``````input_string = input("Enter a string here: ")
counter = 0

for n in input_string :
if n.isspace() != True:
counter = counter + 1
print("Total number of characters in the String is: ",counter)``````

Keep solving. Thanks.

## Related questions

7 views
Problem: Please, pull me up. Thanks a lot for your valuable time: Number of characters in a string python .
15 views
Problem: How can I fix this: get last two characters of string python
35 views
Problem: Hello kodlogs, Recently while studying the string concept in python was doing the string interview preparation in that the question was about how can we accept the last 2 character of the string so I am bit confused, like how can we achieved this and what are the other way to access the last two character of string.
31 views
Problem: Hello kodlogs, Recently while studying the string concept in python was doing the string interview preparation in that the question was about how can we accept the last 2 character of the string so I am bit confused, like how can we achieved this and what are the other way to access the last two character of string.
1 vote
20 views
Problem: Hello guys, I am a Java developer and I&rsquo;ve just started learning and practicing python programming. I found the language very smooth and easy to pick up. Let me come to the point straight, I want to break a String in pieces and add every character into a list. More ... 'y', 't', 'h', &lsquo;o&rsquo;, &lsquo;n&rsquo;] at the end of the program. I wonder if I can do this!
19 views
I require to remove all the special characters, puntuation and and speces from a string?
4 views
Problem: I need to make a program that will read a text file and print how many vowels and consonants there are. I make a text file to test and the only thing in it is "This is a test". However the output it always:Enter the file to check: test.txt.The number of Vowels ... cons I would also like to know, as I get an error when I try to user .lower() to convert everything in the file to lower case.