Answer to Question #333170 in Python for Nah

Question #333170

a)         Method getData: This method reads and stores the data in the two-dimensional list.

 

b)         Method averageHigh: This method calculates and returns the average high temperature of the year.

 

c)         Method averageLow: This method calculates and returns the average low temperature of the year.

 

d)         Method indexHighTemp: This method returns the index of the highest temperature in the list.

 

e)         Method indexLowTemp: This method returns the index of the lowest temperature in the list.


1
Expert's answer
2022-04-24T17:16:37-0400



#[[2021][53,52,63]///]
#two demisional list month[high temp][low temp]
class Temperature:
  def __init__(self):
    """Constructor"""
    self.data=[[0 for x in range(2)]for y in range(12)]
    self.months=["January", "February", "March","April", "May", "June", "July", "August", "September", "October", "November", "December" ]; 
  def getData(self):
    for i in range(12):
      lw=int(input("Please input low temperature for "+self.months[i]+" ="))
      hg=int(input("Please input high temperature for "+self.months[i]+" ="))
      self.data[i][0]=lw
      self.data[i][1]=hg
  def averageLow(self):
    avr=0.0#Return average  low temperature in year
    for i in range(12):
      avr+=self.data[i][0]
    avr/=12
    return avr
  def averageHigh(self):
    """Return ----average high temperatur in year"""
    avr=0.0#Return average  low temperature in year
    for i in range(12):
      avr+=self.data[i][1]
    avr/=12
    return avr
  def indexHighTemp(self):
    num=0
    for i in range(12):
      if self.data[i][1]>self.data[num][1]:
        num=i
    return num
  def indexLowTemp(self):
    num=0
    for i in range(12):
      if self.data[i][0]<self.data[num][0]:
        num=i
    return num
temYear=Temperature()
temYear.getData()
print("Average High:"+str(temYear.averageHigh()))
print("Average Low:"+str(temYear.averageLow()))
print("index High:"+str(temYear.indexHighTemp()))
print("the  Highest Temperature:"+str(temYear.months[temYear.indexHighTemp()]))
print("index Low:"+str(temYear.indexLowTemp()))   
print("the  lowest Temperature:"+str(temYear.months[temYear.indexLowTempTemp()]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS