1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rom4ik [11]
3 years ago
10

Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he o

r she is finished providing inputs. After the user presses the enter key, the program should print:
The sum of the numbers

The average of the numbers

An example of the program input and output is shown below:

Enter a number or press Enter to quit: 1
Enter a number or press Enter to quit: 2
Enter a number or press Enter to quit: 3
Enter a number or press Enter to quit:

The sum is 6.0
The average is 2.0
BASE CODE

theSum = 0.0
data = input("Enter a number: ")
while data != "":
number = float(data)
theSum += number
data = input("Enter the next number: ")
print("The sum is", theSum)
Computers and Technology
1 answer:
kogti [31]3 years ago
5 0

Answer:

theSum = 0.0#defined in the question.

count=0 #modified code and it is used to intialize the value to count.

data = input("Enter a number: ") #defined in the question.

while data != "": #defined in the question.

   number = float(data) #defined in the question.

   theSum += number #defined in the question.

   data = input("Enter the next number or press enter to quit ") #defined in the question "only some part is modified"

   count=count+1#modified code and it is used to count the input to print the average.

print("The sum is", theSum)#defined in the question.

print("The average is", theSum/count) #modified code and it is used to print the average value.

output:

  • If the user inputs as 1,4 then the sum is 5 and the average is 2.5.

Explanation:

  • The above code is written in the python language, in which some part of the code is taken from the question and some are added.
  • The question has a code that tells the sum, but that code is not print the average value of the user input value.
  • To find the average, some codes are added, in which one count variable which is initialized at the starting of the program and gets increased by 1, when the user gives the value.
  • Then that count divides the sum to print the average.
You might be interested in
With an example in each, describe the use of two basic functions which are known by the "string.h" header file.
olga nikolaevna [1]

Answer:

strcmp(char * A, char * B);

strcat(char * A, char * B)

Explanation:

One of these basic functions is the function strcmp(char * A, char * B).

This functions compares if two strings are equal; If they are, it returns 0. If not, it returns 1;

So, an example:

char A[13] = "Buffalo Bills";

char B[13] = "Buffalo Bills";

if (strcmp(A,B) == 0)

printf("The strings are the same\n);

else

printf("The strings are not the same");

In this case, they are the same.

----------------------

If for example:

char B[13] = "Buffalo Billz"

It would fall in the else, A and B would not be the same strings.

--------------------------

Other function is the strcat(char * A, char * B);

This function takes two strings as an input, and concatenate them to the first.

For example:

char A[15] = "Buffalo";

char B[5] = "Bills";

strcat(A, B);

printf("%s\n", A);

The output is:

Buffalo Bills

5 0
3 years ago
On tool hackers use to get sensitive information from victims is/are:
Feliz [49]
Pretty sure it’s keyloggers because it’s the only one that makes sense to me but I’m not 100% sure on that one
5 0
3 years ago
Read 2 more answers
How did technology change the world
Crank

Answer:

Technology has changed the world for the better.

Explanation:

Without technology, many of the things we take for advantage, such as, credit cards, calling people from far distances, heck even being able to call to across the world from where you are right now. Technology has revolutionized many things we use commonly on a day-to-day basis.

3 0
2 years ago
Read 2 more answers
Which type of operation writes the file system structure to the disk?
n200080 [17]
Formatting<span> writes the file system structure to the disk.</span>
8 0
3 years ago
Write a program in c++ to read two integers, calculate and print the smallest
Shalnov [3]

Answer:

#include<iostream>

using namespace std;

int main (){

int n1, n2;

cout<<"Enter 1st number";

cin>>n1;

cout<<"Enter 2nd number";

cin>>n2;

if(n1<n2){

cout<<"The 1st number is the smallest"<<endl<<" is= "<<n1;

}

else{

cout<<"The 2nd number is the smallest"<<endl<<" is= "<<n2;

}

}

return 0;

3 0
3 years ago
Other questions:
  • Putting the word int into a code will create a string variable?
    12·1 answer
  • What are some examples of environmental technology
    8·1 answer
  • Do people answer questions more on this site or be on social more ??? no right or wrong answer your opinion
    6·1 answer
  • Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has no return value.
    8·1 answer
  • You have used loops for repetitive processes.
    11·1 answer
  • Question 8 (True/False Worth 3 points)
    15·1 answer
  • The tag that describes the content of the web page is ________________
    5·1 answer
  • I have a top-secret recipe for the greatest cookie dough I have made and I want to keep the recipe a secret so I apply for a? *
    15·1 answer
  • A web-based program that uses artificial intelligence techniques to automate tasks such as searches is called
    8·1 answer
  • The FCFS algorithm is particularly troublesome for ____________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!