Python Forum
how to get the highest monthly average temperature?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to get the highest monthly average temperature?
#1
my question here
Create a program that reads from a file to display city name and average temperature in Celsius

use !curl to download https://raw.githubusercontent.com/Micros...p_mean.csv as mean_temp.txt

1) open the file in 'r' mode
2) read the first line of text into a variable called: headings and print()
3) convert headings to a list using .split(',') which splits on each comma, print() the list
4) use a while loop to read the remaining lines from the file
5) assign remainging lines to a city_temp variable
6) convert the city_temp to a list using .split(',') for each .readline() in the loop
7) print each city & the highest monthly average temperature
8)close mean_temps

!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt
mean_file=open("mean_temp.txt","r")
headings=mean_file.readline().strip('\n')
print(headings)
heading=headings.split(",")
print(heading)
city_temp=""
city_temp2=[]
headings2=mean_file.readline()
while headings2:
    city_temp+=headings2
    city_temp2.append(headings2.split(","))
    headings2=mean_file.readline()
    
print(city_temp)
print(city_temp2)
for city in city_temp2:
    print(city[0])
Output:

city,country,month ave: highest high,month ave: lowest low
['city', 'country', 'month ave: highest high', 'month ave: lowest low']
Beijing,China,30.9,-8.4
Cairo,Egypt,34.7,1.2
London,UK,23.5,2.1
Nairobi,Kenya,26.3,10.5
New York City,USA,28.9,-2.8
Sydney,Australia,26.5,8.7
Tokyo,Japan,30.8,0.9

[['Beijing', 'China', '30.9', '-8.4\n'], ['Cairo', 'Egypt', '34.7', '1.2\n'], ['London', 'UK', '23.5', '2.1\n'], ['Nairobi', 'Kenya', '26.3', '10.5\n'], ['New York City', 'USA', '28.9', '-2.8\n'], ['Sydney', 'Australia', '26.5', '8.7\n'], ['Tokyo', 'Japan', '30.8', '0.9\n']]
Beijing
Cairo
London
Nairobi
New York City
Sydney
Tokyo

But how to get the highest monthly average temperature?
Reply


Messages In This Thread
how to get the highest monthly average temperature? - by nikhilkumar - Jul-25-2017, 12:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My first temperature converter TheLowEndTheory 7 3,400 Oct-18-2020, 04:39 PM
Last Post: buran
  Monthly pollution rate RbaPhoenix 4 2,695 Mar-28-2020, 04:01 PM
Last Post: ibreeden
  Monthly report for pushed buttons chano 2 2,114 Oct-09-2019, 01:40 PM
Last Post: chano
  Methods that return the highest score from the list erfanakbari1 7 7,126 Mar-26-2019, 08:32 PM
Last Post: aankrose
  Temperature converter Help (ASAP) Edison_Weng 1 2,811 Apr-16-2018, 01:55 PM
Last Post: stranac
  Returning the highest value out of 3 values ComputerSkillet 2 3,842 Apr-28-2017, 03:16 AM
Last Post: volcano63
  Numerically determining the highest a ball travels when shot straight up JakeWitten 3 3,423 Apr-22-2017, 04:37 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020