count = 0
def checkletters(string):
for letter in string:
count +=1
input = input("What string do you want me to check for letter count: ")
checkletters(input)
print(f"There are {count} letters in that string")
I want the script to ask the user to input a string and it will send the amount of letters in the string
>Solution :
There are many ways to resolve this issue i have two for you
1. make you count variable global
global countcount = 0 def checkletters(string): for letter in string: global count count +=1 input = input("What string do you want me to check for letter count: ") checkletters(input) print(f"There are {count} letters in that string")
2. By using count variable inside the function and returning value from that func..
def checkletters(string): count = 0 for letter in string: count +=1 return count input = input("What string do you want me to check for letter count: ") checkletters(input) print(f"There are {checkletters(input)} letters in that string")