Using Python, write the following code.
You are to allow the user to enter the daily temperature as a floating-point number. You should make the assumption that you are recording temperatures in Fahrenheit.
You should allow the user to continue entering temperatures until the value -999 is entered. This number should not be considered a temperature, but just a flag to stop the program. As the user enters a temperature, you should display the following each time:
Current Temperature: 999 F 999 C
Highest Temperature so far 999 F 999 C
Lowest Temperature so far: 999 F 999 C
Average Temperature so far: 999 F 999 C
Note: As much as reasonably possible, the code should be broken down into smaller functions.
Note: you to read a value, process the value, and then throw it away, you do not need an array or a list.
Note: You need to search the WWW to find an equation to convert Fahrenheit into Celsius
Submission Requirements:
Python code:
def ftoc(f):#function to convert Fahrenheit to celcius
return((f-32)*5/9)#return celcius
ctemp=int(input())#accept current temperature
htemp=ctemp#initial high temperature
ltemp=ctemp#initial low temperature
atemp=ctemp#initial average temperature
count=0#variable for finding average
while(ctemp!=-999):#loop till -999 is obtained as input
print("Current Temperature: "+str(ctemp)+"F"+" "+str(ftoc(ctemp))+"C")#printing Current Temperature in Fahrenheit and celcius
if(ctemp>htemp):#checking if new value is the highest
htemp=ctemp#setting high temperature as current temperature
print("Highest Temperature so far: "+str(htemp)+"F"+" "+str(ftoc(htemp))+"C")#printing highest Temperature in Fahrenheit and celcius
if(ctemp<ltemp):#checking if new value is the lowest
ltemp=ctemp#setting low temperature as current temperature
print("Lowest Temperature so far: "+str(ltemp)+"F"+" "+str(ftoc(ltemp))+"C")#printing lowest Temperature in Fahrenheit and celcius
atemp=(atemp*count+ctemp)/(count+1)#setting average temperature
print("Average Temperature so far: "+str(atemp)+"F"+" "+str(ftoc(atemp))+"C")#printing average Temperature in Fahrenheit and celcius
ctemp=int(input())#accept current temperature
count+=1#incrementing count
Screenshot of code:
Input:
Output:
Get Answers For Free
Most questions answered within 1 hours.