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
If nobody buys a ticket to a movie, do they still show it?
Serga [27]

It would depend on the movie and the theater policy.....

Hope this helps have a good day

3 0
3 years ago
Write code to take a String input from the user, then print the first and last letters of the string on one line. Sample run: En
Ainat [17]
<h2>Answer:</h2>

//import the Scanner class to allow for user input

import java.util.Scanner;

//Begin class definition

public class FirstAndLast{

   //Begin the main method

    public static void main(String []args){

       

       

       //****create an object of the Scanner class.

       //Call the object 'input' to receive user's input

       //from the console.

       Scanner input = new Scanner(System.in);

       

       //****create a prompt to tell the user what to do.

       System.out.println("Enter the string");

       

       //****receive the user's input

       //And store it in a String variable called 'str'

       String str =  input.next();

       

       //****get and print the first character.

       //substring(0, 1) - means get all the characters starting

       //from the lower bound (index 0) up to, but not including the upper

       //bound(index 1).

       //That technically means the first character.

       System.out.print(str.substring(0,1));

       

       //****get and print the last character

       //1. str.length() will return the number of character in the string 'str'.

       //This is also the length of the string

       //2. substring(str.length() - 1) - means get all the characters starting

       // from index that is one less than the length of the string to the last

       // index (since an upper bound is not specified).

       // This technically means the last character.

       System.out.print(str.substring(str.length()-1));

       

       

       

    }  // end of main method

   

} //end of class definition

<h2>Explanation:</h2>

The code has been written in Java and it contains comments explaining important parts of the code. Kindly go through the comments.

The source code and a sample output have also been attached to this response.

To run this program, copy the code in the source code inside a Java IDE or editor and save it as FirstAndLast.java

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
4c53f66d970acf88b251b2cf41bcdaf6.png
3 0
3 years ago
Tech A says that no matter which way the vehicle turns, the inside wheel must always turn less sharply than the outside wheel. T
vodomira [7]
The answer is c because the perpendicular bicector alligns.
5 0
3 years ago
How does the technology affect you daily living? Give situations where you use technology and how it helped you.​
Fiesta28 [93]

Answer:

Great!

Explanation:

I use mobile phone and i use it as exmergency phone

5 0
3 years ago
A top level class may have only the following accessmodifier.
GREYUIT [131]

Answer: Public

Explanation:

 A top level class can have a public, as top level cannot be private and protected because the modifier private is not allowed. As, top level is a class which is not a nested class. Interface of a access modifier is either public or no modifier. There are two types of access control modifier are top level - public and member level- private, protected.

3 0
3 years ago
Other questions:
  • Sniffing network and wireless traffic, intercepting bluetooth traffic, and even using equipment to remotely pull information fro
    12·1 answer
  • A name given to a spot in memory is called:
    5·1 answer
  • What are the three modes of the 3D transform manipulator
    12·1 answer
  • Which of the following was the name of the first generation of cell phone networks?
    14·1 answer
  • Match the ernerging technologies to their descriptions.
    14·1 answer
  • Please help me with Excel!!! A lot of points!
    11·1 answer
  • 8.5 Edhesive Code Practice
    14·1 answer
  • Answered
    10·1 answer
  • ____ is an example of a set of prewritten classes that allows you to access data stored in a database.
    8·1 answer
  • What job does a front-end developer perform?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!