Ask coding questions

← Back to all posts
Module 4 assesment python
kanisha123 (0)

question
The Weather
Create a program that:
imports and opens a file
appends additional data to a file
reads from the file to displays each city name and month average high temperature in Celsius
Output: The output should resemble the following

City of Beijing month ave: highest high is 30.9 Celsius
City of Cairo month ave: highest high is 34.7 Celsius
City of London month ave: highest high is 23.5 Celsius
City of Nairobi month ave: highest high is 26.3 Celsius
City of New York City month ave: highest high is 28.9 Celsius
City of Sydney month ave: highest high is 26.5 Celsius
City of Tokyo month ave: highest high is 30.8 Celsius
City of Rio De Janeiro month ave: highest high is 30.0 Celsius
all of the above text output is generated from the file
the only strings are hard coded:

"is"
"of"
"Celsius"
import the file into the Jupyter Notebook environment
use !curl to download https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv as mean_temp.txt

[ ] The Weather: import world_mean_team.csv as mean_temp.txt into the Jupyter notebook

Add the weather for Rio
Open the file in append plus mode ('a+')
Write a new line for Rio de Janeiro "Rio de Janeiro,Brazil,30.0,18.0\n"
Grab the column headings
use .seek() to move the pointer to the beginning of the file
read the first line of text into a variable called: headings
convert headings to a list using .split(',') which splits on each comma

[ ] The Weather: open file, read/print first line, convert line to list (splitting on comma)

Read the remaining lines from the file using a while loop
assign remaining lines to a city_temp variable
convert the city_temp to a list using .split(',') for each .readline() in the loop
print each city & the highest monthly average temperature
close mean_temps
my ans exam_file=open('mean_text.txt', 'a+')
while len(city_temp) == len(headings)
exam_file.write("Rio de Janeiro,Brazil,30.0,18.0\n")

exam_file.seek(0)
headings=exam_file.readline().split(",")
 
exam_file.seek(0,1)
city_temp=exam_file.readline().split(",")
 
while city_temp:
    print(headings[0].capitalize()+" of "+city_temp[0]+" "+ headings[2]+" is "+city_temp[2]+" Celsius")
    city_temp = exam_file.readline().split(",")
 
exam_file.close()

can u pls tell where hav i gone wrong fast pls..with the proper code wud be preferable