Python Forum
counting chars in string w/o len
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
counting chars in string w/o len
#1
Here's my homework assignment:

Write code to count the number of characters in original_str using for loop as a counter and assign the answer to a variable num_chars. Do NOT use the len function to solve the problem.

#Here's my attempt:

original_str = "The quick brown rhino jumped over the extremely lazy fox."
counter=0
for counter in range (original_str):
	counter = counter +  1
num_chars=counter
print(num_chars)
Here's error message:
TypeError: start must be a integer on line 3
Reply


Messages In This Thread
counting chars in string w/o len - by johneven - Mar-20-2019, 06:23 PM
RE: counting chars in string w/o len - by nilamo - Mar-20-2019, 07:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Counting the number of occurrences of characters in a string nsadams87xx 1 1,938 Jun-16-2020, 07:22 PM
Last Post: bowlofred
  slicing and counting words in a string Rudy 11 6,467 Mar-17-2019, 10:46 PM
Last Post: micseydel
  Counting only letters in a string PraiseYAH 2 4,564 Jul-20-2018, 11:22 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020