My program takes input from the user, counts the number of letters in the string, adds them to a variable and then divides the total of that variable by the number of words entered to get the average. I'm finding that I'm getting inconsistent results for my averages. What am I doing wrong?
word_length_count = 0
count = 0
average = 0
word = input("Enter a word (press Enter to quit): ")
count = count + 1
word_length_count = round(word_length_count + len(word))
average = len(word)
while count == 1:
word = input("Enter a word (press Enter to quit): ")
if word == "":
break
else:
while word != "":
word = input("Enter a word (press Enter to quit): ")
count = count + 1
word_length_count = round(word_length_count + len(word))
average = round(word_length_count / count)
print("The average length of the words entered is", round(average))
source https://stackoverflow.com/questions/77294226/inconsistent-average-results-for-while-loops
Comments
Post a Comment