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
AysviL [449]
3 years ago
9

Write a program that asks the user for several days' temperatures and computes the average temperature for that period and how m

any days were above average. First ask the user how many days he\she wants to calculate the average for. Then create an array with that number and ask for the temperature of each day. Store the temps in the array. Then find the average and the number of days above that average. Print the results to the screen.

Computers and Technology
1 answer:
elena-14-01-66 [18.8K]3 years ago
4 0

Answer:

#section 1

<em>no_of_days= int(input('How many days are we geting the average for: ')) </em>

<em>tem=[] </em>

<em>for i in range(no_of_days): </em>

<em>    a= int(input('Enter temperaure: input ' + str(i+1)+'  :')) </em>

<em>    tem.append(a) </em>

<em />

#section 2<em>     </em>

<em>average = round(sum(tem)/len(tem),2) </em>

<em>print('The Average is ',average) </em>

<em>gdays=[] </em>

<em>for i in tem: </em>

<em>    if i > average: </em>

<em>        gdays.append(i) </em>

<em> </em>

<em>print('The following days are greater than the average: ',gdays)</em>

Explanation:

The above code is written in python 3

#section 1:

An input is gotten for number of days that is to be used in the calculation, and an array is created to hold the temperature that will be inputted into the program.

A range of values from [0 - (no_of_days - 1)] is created from the number of days entered, this is done so that the FOR loop can iterate through every number and call for inputs.

The FOR loop prompts the user for an input based on the range and passes that input to an integer data type before appending it to the tem array.

#section 2:

The sum of the new list and the length is used to calculate the average and the it is rounded up to 2 DP, The average is then printed to the screen.

Another FOR loop is used to check which of the days are greater than the average and passes it to another array (<em>gdays)</em>, this array is also printed to the screen.

check the attachment to see how the code works.

You might be interested in
Write a bool function isPalindrome that takes one string parameter and returns true if that string is a palindrome and false oth
kkurt [141]

Answer:

Here is the bool function isPalindrome:

bool isPalindrome(string s)

{  bool palindrome;      

 int j;

 int len = s.length();

 for (int i =0, j= len-1; i < len/2; i++, j--)  

   if (s[i] == s[j])

     palindrome = true;  

   else

     palindrome = false;

 return palindrome; }

Explanation:

The bool function isPalindrome takes a string as parameter and returns true if the string is a palindrome or false if the string is not palindrome. The string variable s holds the string value. In function isPalindrome, there is a bool type variable palindrome. bool is a data type which is used to hold values true or false which is then stored in the palindrome variable.

Next it is being found that how many characters are there in the input string using length() function which returns the length of the string. The length of the string is stored in int type variable len.

Next the for loop starts which has two variables i and j where i starts at 0 position of the input string and j starts at the last position of the string. These two variables move or traverse along the string this way. i variable stops when half the length of the input string is reached. At the end of every iteration i moves forward by the increment of its value to 1 and j moves backwards by the decrement  of its value to 1.

Every the body of  the loop executes, there is an if condition in the body of the loop which checks if the string is a palindrome. This is checked by matching the character at position/index i with the character at position j of the string. This will continue character by character until the i reached half the length of the input string and if every character in i was matched to every character in j then palindrome = true; statement is executed which returns true as the string is a palindrome otherwise palindrome = false; is returned as the string is not a palindrome.

For taking input string from the user and to check if the function isPalindrome() works correctly a main() function is written which takes input string from the user and reads in variable str calls isPalindrome() function. If the string is palindrome then the cout statement in main() function prints the message: String is a palindrome and if the input string is not a palindrome the the following message is displayed in the output screen: String is not a palindrome

int main()

{

string str;

cout<<"Enter a string: ";

cin>>str;

if(isPalindrome(str))

cout<<"String is a palindrome";

else

cout<<"String is not a palindrome";

}

The screenshot of the program along with the output is attached.

7 0
2 years ago
The process of a web server adding a tcp header to a web page, followed by adding an ip header, and then a data link header and
kumpel [21]
<span>Encapsulation is defined as the process of adding a header in front of data supplied by a higher layer (and possibly adding a trailer as well).</span>
7 0
3 years ago
Which of these is not a feature of a CPU?<br><br>Multicore<br>64-Bit Processing<br>L1 Cache<br>DDR
Triss [41]

Answer:

DDR

Explanation:

DDR is a feature of memory. It means a double data rate and is a more sophisticated version of the SDRAM, which is a memory. And the rest like the Multicore, 64-bit processing, and the L1 cache are the features of the CPU. And hence, the correct option here is none other than DDR. Remember that the L1 cache is the memory bank, which is being built over the CPU chip. And we have 32 bit and 64-bit processing for the CPU. As well as CPU can be dual-core, quad-core and likewise.

4 0
3 years ago
Read 2 more answers
What computer has special software that allows it to deliver web pages to the Internet?
Vlad1618 [11]
Web browser (Google Chrome, Safari, Internet Explorer, Edge, etc. )
3 0
3 years ago
Read 2 more answers
Ria has modified the hard disk that hosts the operating system by using the fdisk command. The fdisk command indicates that the
pickupchik [31]

Answer:

a and d

Explanation:

A. Run the parted command

D. Reboot the system

These two actions will make it easier to manually reload the fdisk

8 0
3 years ago
Other questions:
  • Which of the following is a template definition?
    5·1 answer
  • Lesson 15: Integrated Literacy Connections Education Introduction to Computer Applications Unit 6: Internet Safety
    5·1 answer
  • Which one of the following will not be considered as a microcomputer?
    12·2 answers
  • PreparedStatement ps = connection.prepareStatement("select firstName, mi, lastName from Student where lastName = ?"; ps.setStrin
    5·1 answer
  • After Lola gave her friend the password to a protected website, her friend was able to remember it only long enough to type it i
    7·1 answer
  • what you can do to increase your chances of getting employed with changes to your current digital footprint​
    6·1 answer
  • Fire Tint, Inc., (FTI), applies tint to airplane canopies (front windows) manufactured by other companies. When the canopy manuf
    12·1 answer
  • How can we avoid falling victim to a phishing or pharming scheme
    14·1 answer
  • In order to get the maximum functionality out of a device that is plugged in, a user should download the specific ___ for that d
    10·2 answers
  • Viruses that load from usb drives left connected to computers when computers are turned on are known as.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!