Question

There are 3 types of iteration constructs. What ones did you use in your program, and...

  • There are 3 types of iteration constructs. What ones did you use in your program, and why?

NUMS=4
i=1
lowMean=0
dayLow=0
dayHigh=0
highMean=0
highTemp=0
lowTemp=41
#Decalred required vriables
print("--== Python Temperature Analyzer ==--")
while(i<=4):
    high=int(input("Enter the high value of day"+str(i)+":"))
    low=int(input("Enter the low value of day"+str(i)+":"))
    #Reading high and low
    while(high>40 or high<-40 or low>40 or low<-40 or low>high):
        #if the conditons fails we again read the input
        print("Incorrect values, temperatures must be in the range -40 to 40, high must be greater than low.")
        high=int(input("Enter the high value of day"+str(i)+":"))
        low=int(input("Enter the low value of day"+str(i)+":"))
    if(highTemp<high):
        #storing the high temparature
        highTemp=high
        dayHigh=i
    if(lowTemp>low):
        #storing the low temparature
        lowTemp=low
        dayLow=i
    lowMean+=low
    highMean+=high
    #adding hte high and low temparatures to highMean and lowMean
    i+=1
print("The average (mean) LOW temperature was:{:.2f}".format(lowMean/4))
#printing the mean of the low temparaature
print("The average (mean) HIGH temperature was:{:.2f}".format(highMean/4))
#printing the mean of the high temparaature
print("The average (mean) temparture was:{:.2f}".format((highMean/4+lowMean/4)/2))
#printing the mean of the temparature
print("The highest temparature was "+str(highTemp)+" on day " +str(dayHigh))
#printing the high temparature and its day
print("The lowest temparature was "+str(lowTemp)+" on day " +str(dayLow))
#printing the low temparature and its day

Homework Answers

Answer #1

while loop is used in the program.

Because while loop runs until it's condition becomes false.

For the program , this property for while loop is necessary

1) while loop is used because it needs only condition statement but for - for loop it need membership operator and sequence to iterate. for loop can be used by calling range function. so that it will iterates through sequence of numbers.

2) Inner while loop takes input until user enters valid temperatures for the day that mean if user enters invalid temperatures the request again to input a valid temperatures. this while loop is necessary for input data errror checking and it's the only one way to do.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking option entered by the user print("Enter 0 to 5 for following options: ") print("0-> Issue new ticket number.") print("1-> Assign first ticket in queue to counter 1.") print("2-> Assign first ticket in queue to counter 2.") print("3-> Assign first ticket in queue to counter 3.") print("4-> Assign first ticket in queue to counter 4.") print("5-> Quit Program.") tickets = [] #Declaring list to store...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
Consider the following research study: you wish to determine whether or not climate change will impact...
Consider the following research study: you wish to determine whether or not climate change will impact the feeding behavior of vampire bats. You divide a sample of bats into two groups and keep them in cages, each bat in its own individual cage. The first group is kept at a temperature of 30°C, which (we'll pretend) is about average for their natural habitat. The second group is kept in cages in a lab next door at 33°C. All of the...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following commands do: dd, y3, p, :set cindent (1 pt) VIM exercises These exercises on the computer need to be repeated by each student in the pair. This is to ensure that both students understand how to get around in Linux!!! For this part of the lab, you will create a .vimrc file that will help you develop your C++ programs using VIM. First, we...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...
provide 3-4 paragraphs post (team 2) 1-What are 4 key things you learned about the topic...
provide 3-4 paragraphs post (team 2) 1-What are 4 key things you learned about the topic from reading their paper? 2-How does the topic relate to you and your current or past job? 3-Critique the paper in terms of the organization and quality.1- Employee Stress and how it has an Adverse Effect on a Company This paper explores employee stress and how it has an adverse effect on a company, its employees and the organization. Job stress can have a...
for the scenario below: 1) Apply the qualitative analysis by identifying at least 3 issues in...
for the scenario below: 1) Apply the qualitative analysis by identifying at least 3 issues in the above process. Analyse these issues by using a. Adding-value and Waste Analysis b. Issue register, If you find that there are more than three issues, you can focus on the three issues that have the highest impact. 2). Calculate the cycle time efficiency of the as-is process. You can assume a working week of 40 hours. In case there is missing information, you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT