# Noemi Cabrera
# 15 November 2021
# In this project, I practiced using the different methods I learned to open, close, convert
# into a list, move the pointer, and write in a imported file. I created a weather program
# combining these methods that imports and opens a file, appends additional data to the file,
# and reads from the file to displays each city name and month average high temperature in Celsius.
# One small difficulty I had was that an 'out of index' error displayed. After checking
# everything in the code and checked if the new line for Rio de Janeiro was written in the file,
# I realized the "\n" formatting character I placed in the line was causing the error. So, I
# removed the '\n' when I wrote the text to the file.
# In this code, I created a program that displays the month average high temperature in Celsius of specific
# cities located in a file. A file is imported using the curl statement. The file is named mean_temp. The
# mean_temp.txt file is opened in 'a+' mode with the open() metho and then new text is added to it using
# the .write() method. The pointer is set to the beginning of the file using seek(0).Then, the file is read line by
# line with the readline() method. The file contents are converted into a list of items using the split() method,
# which is stored in the headings variable. The headings list is printed. Lastly, the mean_temp file is read line
# by line each saved as a string. Then, a while loop is used to display each city name and month average high
# temperature in Celsius. To do this, the temp_list was created with the strings of the mean_temp file. The file is closed.
# [] create The Weather
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt
mean_file = open("mean_temp.txt","a+")
mean_file.write("Rio de Janeiro,Brazil,30.0,18.0")
mean_file.seek(0)
headings = mean_file.readline().split(",")
print(headings,"\n")
city_temp = mean_file.readline()
while city_temp:
temp_list = city_temp.split(',')
print(headings[2] + " for " + temp_list[0] + " is " + temp_list[2] + " Celsius")
city_temp = mean_file.readline()
mean_file.close()