I created a function that would count the number of characters in a string with this code:
def count_characters_in_string(mystring):
s=0
x=mystring
for i in x:
t=i.split()
s=s+len(t)
print("The number of characters in this string is:",s)
count_characters_in_string("Apple")
This is what it returns: The number of characters in this string is: 1 The number of characters in this string is: 2 The number of characters in this string is: 3 The number of characters in this string is: 4 The number of characters in this string is: 5
Is there a way to only print the last line so that it prints:
The number of characters in this string is: 5