• Register
2 votes
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.

Please, pull me up. Thanks a lot for your valuable time.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes
 
Best answer

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.

13 9 6
94,260 points

Related questions

0 votes
1 answer 7 views
7 views
Problem: Please, pull me up. Thanks a lot for your valuable time: Number of characters in a string python .
asked Mar 15 Wafa Abu Yousef 6.1k points
0 votes
1 answer 15 views
15 views
Problem: How can I fix this: get last two characters of string python
asked Mar 15 Wafa Abu Yousef 6.1k points
0 votes
1 answer 35 views
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.
asked Jun 17, 2020 Gavin 15.3k points
3 votes
1 answer 31 views
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.
asked Jun 11, 2020 Gavin 15.3k points
1 vote
1 answer 20 views
20 views
Problem: Hello guys, I am a Java developer and I’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', ‘o’, ‘n’] at the end of the program. I wonder if I can do this!
asked Jun 2, 2020 adamSw 11.3k points
0 votes
1 answer 19 views
19 views
I require to remove all the special characters, puntuation and and speces from a string?
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
1 answer 4 views
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.
asked 2 days ago Humaira ahmed 50.7k points
0 votes
1 answer 3 views
3 views
Problem: I am attempting to iterate over the following string, using a for loop: >>> for a,b,c in "cat" print(a,b,c) Now what I intended for this to do was print out each character in the string individually on one physical line, instead I receive an error. I am aware that this is ... list operator []: >>> for a,b,c in ["cat"] print(a,b,c) c a t But could someone explain why this is the case?
asked 4 days ago ochena 22.1k points
0 votes
1 answer 25 views
25 views
I have to remove special characters from a string using PHP. Can any one here give me the PHP Script?
asked Sep 25, 2020 Daniel Anderson 4k points
1 vote
1 answer 4 views
4 views
Problem: I am unable to find out the solution, Please solve it : python count number of characters in string
asked Mar 30 MUHAMMAD MUNEEB 83k points