Question

In: Computer Science

Write a program that prompts the user to enter a series of strings, but with each...

Write a program that prompts the user to enter a series of strings, but with each string containing a small integer. Use a while loop and stop the loop when the user enters a zero. When the loop has finished, the program should display:

  • the number of user inputs (not counting the final zero input).
  • the total of the integers in the strings entered.
  • the average of the integers accurate to one decimal place.

Any help is greatly appreciated, this is for python 3

I am not given any more information. this is all the professor has told me

Solutions

Expert Solution

import re

total_inputs = 0
sum_of_numbers = 0

# Ask user to enter string
input_string = input('Enter a string: ')

# Check if string is not 0
while input_string != '0':
    # Increment total_inputs by 1
    # Find integer in string and store in num
    # Add num to sum
    total_inputs += 1
    num = re.findall('\d+', input_string)[0]
    sum_of_numbers += int(num)
    # Ask user to enter string again
    input_string = input('Enter a string: ')

# Calculate average
average = sum_of_numbers / total_inputs

# Display result
print('\nNumber of user Inputs:', total_inputs)
print('Total of the integers:', sum_of_numbers)
print('Average of the integers: %.1f' % average)

SCREENSHOT-

OUTPUT


Related Solutions

Exercise 3 – Strings Using a function Write a program that prompts the user to enter...
Exercise 3 – Strings Using a function Write a program that prompts the user to enter two inputs: some text and a word. The program outputs the starting indices of all occurrences of the word in the text. If the word is not found, the program should output “not found”. Example1: Input1: my dog and myself are going to my friend Input2: my Output: 0 11 31 Example 2: Input1: Programming is fun Input 2: my Output: not found
JAVA Write a test program that prompts the user to enter a series of integers and...
JAVA Write a test program that prompts the user to enter a series of integers and displays whether the series contains runLength consecutive same-valued elements. Your program’s main() must prompt the user to enter the input size - i.e., the number of values in the series, the number of consecutive same-valued elements to match, and the sequence of integer values to check. The return value indicates whether at least one run of runLength elements exists in values. Implement the test...
Write a program that prompts the user to enter the number of students and each student’s...
Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score and the student with the second-highest score. Use the next() method in the Scanner class to read a name rather using the nextLine() method. This is my code , but i get this error Enter the number of students: Exception in thread "main" java.util.InputMismatchException    at java.util.Scanner.throwFor(Scanner.java:871)    at java.util.Scanner.next(Scanner.java:1494)    at...
This assignment involves developing a program that prompts the user to enter a series of 10...
This assignment involves developing a program that prompts the user to enter a series of 10 integers and then determines and displays the largest and smallest values entered. Your solution must use at least the following variables: counter: A counter to count how many integers were entered a Number: The integer most recently input by the user, smallest: The smallest number entered so far, largest: The largest number entered so far. Write three separate programs for this assignment: Name the...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Write a program that prompts the user to enter three sets of five double numbers each....
Write a program that prompts the user to enter three sets of five double numbers each. (You may assume the user responds correctly and doesn’t enter non-numeric data.) The program should accomplish all of the following: a. Store the information in a 3×5 array. b. Compute the average of each set of five values. c. Compute the average of all the values. d. Determine the largest value of the 15 values. e. Report the results. Each major task should be...
JAVA Write a program that will compare two names. The program prompts the user to enter...
JAVA Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are same, the program states that. If the names are different, the program converts both names to UPPERCASE, and compares then again. If they are equal, the programs displays a message stating that names are equal if CASE is ignored. Otherwise, the program prints names with a message that names are not equal.  Check also if there...
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT