0

I am writing a program that allows a user to input a string and the program will count the number of characters only (no spaces and punctuation). For waht I have used I ma trying to use a for loop that goes through all the characters of the string and will increment the count value if the value is not a psace or punctuation. Howeevre it s not working and its giving me an error that my string input is an integer even though python will autromatically convert to string

What I have tried is to use the toString method but that didnt work for some reason. For example if I were to input "Hello World!" to the program it will print out "Length is 10"

this is my code here

input = input("enter a string: ")

count = 0

for i in len(input):
if (input(i) == "," or input(i) == " " or input(i) == "!" or input(i) == "."):
i += 1
else:
count += 1

print("Length is: " + count + " characters")
Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
  • use `for i in len(range(input)):` – bn_ln Oct 31 '22 at 06:37
  • 2
    Part of your confusion comes from using a variable with the name of a standard function. Once you create `input`, you can no longer access the `input` function. And to reference a character in a string, you use square brackets: `input[i]`. – Tim Roberts Oct 31 '22 at 06:37

0 Answers0