vendredi 19 novembre 2021

Printing each individual user input and it's values from a loop?

I have to create a loop and end it when the user enters "end" and then print out what the user input and the "values" of that string. It should display how many numbers, letters, amount of uppercase or lowercase letters, and how many white space characters there are. THEN print out the total number of all those values from every input.

My problem is that my code is adding up values for every input and printing that not just the values for each individual string.

lower_count = 0
upper_count = 0
lower_total = 0
upper_total = 0
whitespace_count = 0
whitespace_total = 0
numeric_count = 0
alphabetic_count = 0
while True:
    UserInput = str(input("Enter a string (enter 'end' to end): "))
    for entry in UserInput:
        if UserInput == 'end': break
        if (entry.islower()):
            lower_count += 1
        else:
            upper_count += 1
        if entry == ' ' or entry == '\n':
            whitespace_count += 1
        if entry.isdigit():
            numeric_count += 1
        elif entry.isalpha():
            alphabetic_count += 1
print(UserInput)
print("The amount of whitespace is:", whitespace_count)
print("The amount of lower case letters:", lower_count)
print("The amount of upper case letters:", upper_count)
print("The amount of numerical characters is:", numeric_count)
print("The amount of alphabetical characters is:", alphabetic_count)

Aucun commentaire:

Enregistrer un commentaire