====================================================================== ===== COMP2720 ===== Semester 2, 2006 ===== Lab sheet ===== ====================================================================== Student name: Dean Dal Broi Student Uni ID: u4222206 Lab goup: Wed 10-12 Tutor: Peter Christen ---------------------------------------------------------------------- Lab number: 5 Date: 27/9/06 ====================================================================== Completed Lab Preliminaries. Part 1. Q1. Have downloaded the latest weather file and have run the getWeather program on it and have found that it list the cities that have weather data in the weather file. It does however contain an error as the first city printed is '+---------' which is not listed in the file as a city with weather data. Q2. Have extended the getWeather program to print each city's temperature and weather conditions. modified the following code to achieve this: from this: print "City:", obs[:11] to this: print "City:", obs[:11], obs[44:47], "degC ", obs[66:71] Q3. Can tally any weather condition by searching for the condition with an if statement and then if the condition is met adding 1 to the tally. for obs in weatherList if (obs[66:70] == 'Snow'): snowcities = snowcities + 1 print "Number of cities with snowy conditions: ", snowcities Can get the global average temperature with the following: for obs in weatherList: if (obs[44:47] != ' --'): totaltemps = totaltemps + (int(obs[44:47])) count = count + 1 print "Average Global Temperature:", (totaltemps/count), "degC" Also picked out global max and min temps: for obs in weatherList: if (obs[44:47] != ' --'): if (int(obs[44:47])) > maxtemp: maxtemp = (int(obs[44:47])) maxtempStation = obs[:11] if (obs[44:47] != ' --'): if (int(obs[44:47])) < mintemp: mintemp = (int(obs[44:47])) mintempStation = obs[:11] print "Maximum Global Temperature:", maxtemp, "Observed at:", maxtempStation print "Minimum Global Temperature:", mintemp, "Observed at:", mintempStation Q4. Have written the function getWeatherIn(City). It is basically the same as the other function getWeather, the only different is it takes in a string for the city name and the counts how may characters are in that string: wordlength = len(City) It then searches for that city in the observations and prints its weather data: for obs in weatherList: if (City == obs[:wordlength]): print "City:", obs[:11], obs[44:47], "degC ", obs[66:71] Part 2. Q1. Have ran the program sinePictureSound and have save its output as pic and snd. have viewed and pic and played as well as viewed snd. Q2. Have commented the program to my understanding of how it works. Q3. Have corrected the sinePictureSound function so that it doesnt create a sharp dip in the sound at the top of each sound wave, This was done with an If statement checking the sample value to be set didnt exceed the maximum allowable value in the sound. If the condition was met, the the sample value was set to the maximum Q4. Have created the triangularPictureSound function based largely on the triangleWave function from lab 4. This was very difficult to work out. The main loop does what the triangleWave functions main loop does but also creates a color value for the current sound sample and sets that in the current pixel. ======================================================================