Ask Question
24 January, 08:31

Write a program that prompts a user to enter numeric values. As each value is entered, the program should: - Append the value to a list - Display the values of the list - Display the updated average of the list - Continue to prompt until the user enters any of: quit, stop, or end. Allow upper or lower case

+5
Answers (1)
  1. 24 January, 10:18
    0
    Following are the program in the Python Programming Language:

    my_lst=[] #set list

    while (True) : #set while loop

    print ("Enter stop, end or quit to stop the loop")

    n=input ("Enter the number of elements: ")

    #get input from user

    if (n=="quit" or n=="QUIT" or n=="stop" or n=="STOP" or n=="end" or n=="END") : #set if statement for break the loop

    print (n)

    break

    else: #set else statement

    a=int (n) #type conversion

    for num in range (0, a) : #set for loop

    l=float (input ("Enter the element for list: ")) #get elements of list

    my_lst. append (l) #elements append to the list

    print ("List: ", my_lst) #print list

    print ("Average of the list:", sum (my_lst) / a)

    #print average of the list

    Output:

    Enter the number of elements: 5

    Enter the element for list: 1

    Enter the element for list: 2

    Enter the element for list: 3

    Enter the element for list: 4

    Enter the element for list: 5

    List: [1.0, 2.0, 3.0, 4.0, 5.0]

    Average of the list: 3.0

    Enter the number of elements: STOP

    STOP

    Explanation:

    Here, we set list data type variable "my_lst" then, we set the while loop statement and pass condition "True" and inside it.

    Then, we set a variable "n" and get input from the user in it. Then, we set the if statement and pass the condition is when user input stop, end, or quit then loop is break. Then, otherwise we set the variable "a" and the value of "n" is converted into the integer and store into "a". Then, we set the for loop statement inside the else statement which starts from 0 to n inside the loop. Then, we set the variable "l" which stores the elements of the list from the user in float data type. Then, we append the elements of the "l" into the list "my_lst" and end for loop. Finally, we print the list with message and then print average with message.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that prompts a user to enter numeric values. As each value is entered, the program should: - Append the value to a list - ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers