In: Computer Science
The following table represents the average temperatures in San
Francisco for the first three
months of 2017 and 2018. Use Python
2017 2018
Days Jan Feb March Jan Feb March
1 50 52 42 51 62 54
2 48 57 43 55 62 51
3 52 58 44 55 63 48
4 52 57 51 58 64 48
5 46 56 50 59 63 51
1. Using this table, create 2 Nested Lists, one for each
year.
Call those lists temp_2017 and temp_2018.
Each of those lists is composed of 3 sequence of values. Each
sequence corresponds to a
month and is composed of 5 temperatures.
2. Using the created nested lists, write a script that
display:
a. The temperatures for each of the first 5 days of February
2017
b. The temperatures for each of the third, fourth and fifth day of
March 2018
c. The temperature for January 3rd, 2018
data.txt:
Days,Jan,Feb,March,Jan,Feb,March
1,50,52,42,51,62,54
2,48,57,43,55,62,51
3,52,58,44,55,63,48
4,52,57,51,58,64,48
5,46,46,50,59,63,51
#code:
f=open("date.txt","r")
hole_data=[]
for l in f.readlines():
temp=l.replace("\n","")
hole_data.append(temp.split(","))
main_list=[]
months=hole_data[0]
for i in range(0,7):
sub_list=[]
for j in range(1,6):
sub_list.append(int(hole_data[j][i]))
main_list.append(sub_list)
output=[]
for i in range(1,len(main_list)):
sub=[months[i],main_list[0],main_list[i]]
output.append(sub)
temp_2017=output[0:3]
temp_2018=output[3:]
print(temp_2017)
print(temp_2018)
print("Feb:",temp_2017[1])
print("March: Third {} forth {} fifth {}
".format(temp_2018[2][2][2],temp_2018[2][2][3],temp_2018[2][2][4]))
print("Jan: Third {} 2018".format(temp_2018[0][2][2]))
#output:
#if you have any doubts comment below...