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
sergey [27]
3 years ago
6

Count positive and negative number and compute the average. The program will have the user input an unspecified number of intege

rs.
Determine how many are positive and negative.
Compute the total and average. Use a while loop.
Output as follows:
Enter an integer, the input ends if it is 0: 1 2 -1 3 0
The number of positives: 3
The number of negatives: 1
The total is 5.0
The average is 1.25
Computers and Technology
1 answer:
Alla [95]3 years ago
3 0

Answer:

The solution code is written in Python 3

  1. total = 0
  2. count = 0
  3. neg = 0
  4. pos = 0
  5. num = int(input("Enter an integer: "))
  6. while(num != 0):
  7.    total += num  
  8.    count += 1
  9.    if(num < 0):
  10.        neg += 1
  11.    else:
  12.        pos += 1
  13.    num = int(input("Enter an integer: "))
  14. print("The number of positives: " + str(pos))
  15. print("The number of negatives: " + str(neg))
  16. print("The total is " + str(total))
  17. print("The average is " + str(total/count))

Explanation:

Firstly, we create four variables, <em>total</em> , <em>count,</em> <em>neg</em> and <em>pos </em>(Line 1- 4). This is to prepare the variable to hold the value of summation of input integer (<em>total</em>), total number of input number (<em>count</em>), total negatives (<em>neg</em>) and total positives (<em>pos</em>).

Next, we prompt user for the first integer (Line 6).

Create a sentinel while loop and set the condition so long as the current input number, <em>num</em> is not equal to zero. the program will just keep adding the current <em>num</em> to total (Line 9)  and increment the count by one (Line 10).

if <em>num</em> smaller than zero, increment the <em>neg</em> by one (Line 13) else increment the <em>pos </em>by one (Line 15). This is to track the total number of positives and negatives.

Finally, we can display all the required output (Line 20 - 23) using the Python built-in function <em>print()</em>  when user enter 0 to terminate the while loop. The output shall be as follows:

The number of positives: 3

The number of negatives: 1

The total is 5

The average is 1.25

You might be interested in
What port is typically reserved and utilized by the Secure Hypertext Transfer Protocol to create a secure connection to a Web se
jek_recluse [69]

Answer:

Port 443

Explanation:

This is the Hypertext Transfer Protocol Secure that combines the HTTP with a cryptographic protocol, which can be used for payment transactions and other secure transmission of data from Web pages. Whenever you connect to a website beginning with "https://" or you see the lock icon, you’re connecting to that web server over port 443.

4 0
3 years ago
Your organization's network has multiple layers of security devices. When you attempt to connect to a service on the Internet. H
Sindrei [870]

Answer:

The host-based firewall settings are blocking the service

Explanation:

Host-based firewall settings can be configured on each workstation. The firewall can be provided by the operating system itself, or it can be a standalone software package that provides security features and functionality for the device's network connection. If this firewall contains incorrect settings, legitimate services can be blocked, and if so, a message will usually notify the user of such a breach. In these cases, the firewall settings need to be adjusted to make the desired service work.

7 0
3 years ago
write the structure of an email message ques.2 what do you mean by search engine? write its component .ques. 3 what are the adva
loris [4]

Answer:

1.....There is a standard structure for emails. Email contents are primarily classified as two, the header and the body. We are going to see the contents come under the two subparts. The email header gives us common details about the message such as the unique identity of the message.

Explanation:

2......a program that searches for and identifies items in a database that correspond to keywords or characters specified by the user, used especially for finding particular sites on the World Wide Web.

its components are ....

A search engine normally consists of four components e.g. search interface, crawler (also known as a spider or bot),indexer, and database.

3.....Advantages Of eLearning

It is a very efficient way of delivering courses online. Due to its convenience and flexibility, the resources are available from anywhere and at any time. Everyone, who are part time students or are working full time, can take advantage of web-based learning.

hope this will help you ..

please like and mark as brilliant.

4 0
3 years ago
Example of Bandwidth Analogies: using Pipe
skelet666 [1.2K]

Answer:

Bandwidth describes the maximum data transfer rate of a network or Internet connection. ... For example, a gigabit Ethernet connection has a bandwidth of 1,000 Mbps (125 megabytes per second). An Internet connection via cable modem may provide 25 Mbps of bandwidth.

7 0
2 years ago
Read 2 more answers
Play station account
Reika [66]
I have a PlayStation as well
4 0
3 years ago
Read 2 more answers
Other questions:
  • It is better to know the main components of all computer programming languages
    9·1 answer
  • Why is there a need to compare and align one's PECs of a successful entrepreneur?
    5·1 answer
  • When was unicode invented?
    13·1 answer
  • A forensic investigation discovered that accounts belonging to employees who were terminated numerous years ago were recently us
    9·1 answer
  • Suppose that we have a set of activities to schedule among a large number of lecture halls, where any activity can take place in
    8·1 answer
  • Your ___ can provide hardware firewall protection for your home network where it connects to the ISP's network, just as ISP netw
    12·1 answer
  • Write a program in qbasic to accept a character and check it is vowel or consonant​
    14·1 answer
  • Please help I will mark brainliest
    5·1 answer
  • When software is purchased, a _____ is being bought that gives the purchaser the right to use the software under certain terms a
    9·1 answer
  • Which of the following best describes a hotspot as
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!