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
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 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...
Write a test program that prompts the user to enter a sequence of numbers ending with...
Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes this method to return the largest number in the input. Use inheritance and polymorphism approach. in java please
Problem 1 Write a program that prompts the user to enter an integer It then tells...
Problem 1 Write a program that prompts the user to enter an integer It then tells the user if the integers is a multiple of 2, 3, 5, 7 or none of the above. Program language is C Ex. Enter an integer 12 You entered 12 The number you entered is a multiple of 2 ----------------------------------------------- Enter an integer 11 You entered 11 The number you entered is not a multiple of 2, 3, 5, or 7
Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT