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
Nataly_w [17]
1 year ago
8

Edit the program provided so that it receives a series of numbers from the user and allows the user to press the enter key to in

dicate that he or 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

This is what I have but it just keep going with the numbers
# Edit the code below
theSum = 0.0
count = 0
while True:
number= input("Enter a number or press Enter to quit:")
if number=="":
break
theSum+=float(number)
count+=1
print("The sum is", theSum)
if count>0:
print("The average is ", theSum/count)
Computers and Technology
1 answer:
BlackZzzverrR [31]1 year ago
8 0

The edited and complete program is as follows

theSum = 0.0

count = 0

while True:

   number= input("Enter a number or press Enter to quit:")

   if not number:

       print("The sum is", theSum)

       if count>0:

           print("The average is ", theSum/count)

       exit()

   theSum+=float(number)

   count+=1

<h3>How to edit the program?</h3>

The complete program that calculates the average and the sum of numbers entered by the user is as follows:

Note that the program ends when the user presses the enter key and comments are used to explain each line

#This initializes the sum

theSum = 0.0

#This initializes the counter

count = 0

#This ensures the user enters numbers repeatedly

while True:

   #This gets the input

   number= input("Enter a number or press Enter to quit:")

   #When the user presses enter

   if not number:

       #This prints the sum and the average

       print("The sum is", theSum)

       if count>0:

           print("The average is ", theSum/count)

       #This exits the program

       exit()

   #This calculates the sum

   theSum+=float(number)

   count+=1

Read more about python programs at

brainly.com/question/26497128

#SPJ1

You might be interested in
What is the title of RFC 4890 and what year was this RFC published?
Phantasy [73]

Answer:

The title of RFC 4890 is "Recommendations for Filtering ICMPv6 Messages in Firewalls" and it was published in 2007.

Explanation:

RFC 4890 is the memo that was published in 2007. This document is about the recommendations of filtering messages that are harmful and having security risk for Internet Control Message Protocol ICMP version 6.

In this document different types of risk associated ICMPv6 protocol while forwarding messages. This memo recommends filtering techniques to drop the harmful messages and make the communication secure.

4 0
3 years ago
Write a program to test the difference between %d and %i conversion
Gelneren [198K]
Void test(char *s)
{
  int i, d;
  sscanf(s, "%i", &i);
  printf("%s converts to %i using %%i\n", s, i);
  sscanf(s, "%d", &d);
  printf("%s converts to %d using %%d\n", s, d);
}

int main()
{
  test("123");
  test("0x123");
  return 0;
}

outputs:
123 converts to 123 using %i
123 converts to 123 using %d
0x123 converts to 291 using %i
0x123 converts to 0 using %d

As you can see, %i is capable of parsing hexadecimal, whereas %d is not. For printf they're the same.
7 0
3 years ago
Julian downloaded some of the music he created to play for his friend. Julian's friend wore headphones to listen to the music. A
egoroff_w [7]
B) output device

bc you’re using them to listen to something
6 0
3 years ago
Read 2 more answers
Now, extend your test program by adding a second function named split that will identify all the individual values in a comma se
otez555 [7]

Answer:

The code to copy is :

#include <iostream>

#include <string>

using namespace std;

string nextString(string str, int start_index);

int split(string str, string a[], int max_size);

int main()

{

const int VALUES = 20;

string somestring;

string varray[VALUES];

//Prompt the user to enter a comma separated string

cout << "Enter a comma seperated string: ";

//read the string

getline(cin, somestring);

//call split() method on the given string and

//store the count of individual strings in cnt

int cnt = split(somestring, varray, VALUES);

//Print the individual strings

for (int i = 0; i<cnt; i++)

cout << varray[i] << endl;

return 0;

}

//returns a sub string that starts at strat_index

//in the given string and ends before a comma

string nextString(string str, int start_index)

{

int i;

//find a comma or end of the string, after strat_index

for (i = start_index;i < str.length();i++)

{

//if comma is found, exit the loop

if (str.at(i) == ',')

break;

}

//extract the sub string

string out= str.substr(start_index, i-start_index);

return out;

}

//splits the comma separted string as individual strings

//and returns the number of individual strings

int split(string str, string a[], int max_size)

{

int i, j;

int start_index = 0;

//search for commas in the given string

for (i = 0,j=0;i < str.length();i++)

{

//if comma is identified or end of the string is identified

//, then get a strig that starts at start_index using next string

if (str.at(i) == ',' ||i==str.length()-1)

{

//save each string into an array of strings

a[j] = nextString(str, start_index);

//update the next string starting postion(starts after comma)

start_index = i + 1;

j++;

}

}

return j;

Explanation:

Please see attachments

7 0
3 years ago
Wikis are designed for ________, which is allowing people to contribute more than just posting a response
Viefleur [7K]

Answer:

collabirations

Explanation

Wikis are designed for collabirations, which is allowing people to contribute more than just posting a response.

4 0
3 years ago
Other questions:
  • Which two statements are true regarding the user exec mode? (choose two.)?
    6·1 answer
  • Conceptual note-taking is the act of
    15·1 answer
  • William has an internet connection that does not allow him to make calls when connected to the internet. what internet service c
    7·2 answers
  • Technician A says you should measure the parasitic load immediately after the vehicle is turned off. Technician B says you shoul
    10·1 answer
  • The 8086 was divided into two main parts. The _____ was the "brain" of the processor, and had the ALU, general-purpose register,
    10·1 answer
  • A class is a _____, which encapsulates _____ and _____. (Points : 2) programming language construct; attributes; behavior
    7·1 answer
  • All computer systems have
    14·2 answers
  • Write programs in python to display “Valid Voter”. (condition : age of person should be
    15·1 answer
  • Explain why the program did not print "clap", and how to fix it.
    13·1 answer
  • Assume you have written a method with the header num yourMethod(string name, num code). The method's type is ____ .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!