def trend(county): data = [] #NEW LISTS signs = [] first = read_deaths(county) for n in range(len(first) - 1): change = first[n + 1] - first[n] data.append(change) #ADD DATA TO NEW LIST for i in range(len(data)): if data[-1 - i] < -5: # NEGATIVE signs.append('-') elif data[-1 - i] > 5: signs.append('+') #POSITIVE elif -5 < data[-1 - i] < 5: signs.append('=') #LESS THAN 5 EITHER WAY, SO EQUAL print(county + ':' """ 2013 2004 Trend: {} """.format("".join(signs))) return signs.count('+') - signs.count('-') # COUNT TO FIND STATISTICS
elif trendline.count("+") < trendline.count("-"): #Second area is better output = "I would rather live in {} than {}".format(area2, area1) return output else: #Both areas are the same output = "{} and {} are the same".format(area1, area2) return output #main body #Handle the first name and data set name1 = input("Enter the first area to check => ") print(name1) cdata1 = hw4_util.read_deaths(name1) if len(cdata1) == 0: #check name validity print(name1, "is an invalid name") sys.exit() #Handle the second name and data set name2 = input("Enter the second area to check => ") print(name2) cdata2 = hw4_util.read_deaths(name2) if len(cdata2) == 0: #check name validity print(name2, "is an invalid name") sys.exit() #Compute the difference
data_[d] = '+' data__ += data_[d] elif float(data_[d]) <= low: data_[d] = '-' data__ += data_[d] else: data_[d] = '=' data__ += data_[d] print county.ljust(15) + data__ ## main body of program if __name__ == "__main__": county_1 = raw_input('First county => ') print county_1 data_1 = hw4_util.read_deaths(county_1) county_2 = raw_input('Second county => ') print county_2 data_2 = hw4_util.read_deaths(county_2) print ## conditional statements for different cases if data_1 != [] and data_2 != []: print ' ' * 15 + '2013' + ' ' * 3 + '2003' read_deaths(county_1, data_1) read_deaths(county_2, data_2) elif data_1 != [] and data_2 == []: print 'I could not find county %s' % county_2 elif data_1 == [] and data_2 != []: print 'I could not find county %s' % county_1 else:
if count > 0: print('I would rather live in', city1, 'than', city2) elif count < 0: print('I would rather live in', city2, 'than', city1) else: print(city1, 'and', city2, 'are the same') else: print('not equal lists') area1 = input('Enter the first area to check => ') print(area1) dataC1 = hw4_util.read_deaths(area1) # Read data from file ##print(dataC1) if dataC1 == []: # Check if data exists in list print(area1, 'is an invalid name') else: area2 = input('Enter the second area to check => ') print(area2) dataC2 = hw4_util.read_deaths(area2) ## print(dataC2) if dataC2 == []: print(area2, 'is an invalid name') else: deathCount(area1, area2, dataC1, dataC2)
# Author: Yuze Bob Ma # Date: Oct, 9th, 2016 # This code is written for HW4, part 2. # import modules import hw4_util import sys # load the files for the list area_1 = input('Enter the first area to check => ') print(area_1) cdata1 = hw4_util.read_deaths(area_1) if cdata1 == []: print(area_1 + ' is an invalid name') sys.exit() area_2 = input('Enter the second area to check => ') print(area_2) cdata2 = hw4_util.read_deaths(area_2) if cdata2 == []: print(area_2 + ' is an invalid name') sys.exit() # analyse the trend trend = [] for i in range(11): diff = cdata1[i] - cdata2[i] if abs(diff) <= 50: trend.append('=') elif diff < -50: trend.append('+') else:
elif -5 < data[-1 - i] < 5: signs.append('=') #LESS THAN 5 EITHER WAY, SO EQUAL print(county + ':' """ 2013 2004 Trend: {} """.format("".join(signs))) return signs.count('+') - signs.count('-') # COUNT TO FIND STATISTICS #INPUTS first_county = input('Enter the first area to check => ') print(first_county) if read_deaths(first_county) == []: #INVALID NAME print(first_county, 'is an invalid name') sys.exit() second_county = input('Enter the second area to check => ') print(second_county) if read_deaths(second_county) == []: #INVALID NAME print(second_county, 'is an invalid name') sys.exit() print() #CREATE FOR BOOLEANS trend1 = trend(first_county) trend2 = trend(second_county)