Ask Question
20 January, 16:12

Write a program that allows users to enter a series of numbers and displays frequency of each number. Implement the following: 1. The user can enter a maximum of 20 numbers or enter-1 to end the series 2. Only numbers between 0 ... 9 is allowed (or - 1); if the user enters a number outside the valid input, inform the user and ask them to enter a valid number 3. Display the frequency of each number in the output. If the user input is 0,0,1,2,2,4,5,8,8,8,9,9, - 1 the output will be:

+4
Answers (1)
  1. 20 January, 19:02
    0
    zero = one = two = three = four = five = six = seven = eight = nine = 0

    while True:

    number = int (input ("Enter a number: "))

    if number = = - 1:

    break

    elif 0 < = number < = 9:

    if number = = 0:

    zero + = 1

    elif number = = 1:

    one + = 1

    elif number = = 2:

    two + = 1

    elif number = = 3:

    three + = 1

    elif number = = 4:

    four + = 1

    elif number = = 5:

    five + = 1

    elif number = = 6:

    six + = 1

    elif number = = 7:

    seven + = 1

    elif number = = 8:

    eight + = 1

    elif number = = 9:

    nine + = 1

    else:

    print ("Invalid input!")

    print ("0 - > " + str (zero) + "," + " 1 - > " + str (one) + "," + " 2 - > " + str (two) + "," + " 3 - > " + str (three))

    print ("4 - > " + str (four) + "," + " 5 - > " + str (five) + "," + " 6 - > " + str (six) + "," + " 7 - > " + str (seven))

    print ("8 - > " + str (eight) + "," + " 9 - > " + str (nine))

    Explanation:

    Initialize the variables to hold the count for each digit

    Initialize a while loop that iterates until a specified condition is reached

    Inside the loop:

    Get a number from the user and check

    If the number is - 1, stop the loop

    If it is between 0 to 9, increase corresponding count value by 1

    If it is out of range, print an error message

    When the loop is done, print each count variable
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that allows users to enter a series of numbers and displays frequency of each number. Implement the following: 1. The user ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers