This was my code fo the cars WSQ. Once i learn to use files, this becomes easy.
#Jorge Fernando Saldaña Cabal
#A01350730
archivo = open(«carros.txt», «r»)
lineas = archivo.readlines()
#def primero:
y = 0
contcity = 0
for i in lineas:
x = (i[52:54])
if (x != «»):
x = float(x)
y = y + x
contcity = contcity + 1
city = y//contcity
print(‘The average gas mileage in city is: ‘,city)
p = 0
conthigh = 0
for i in lineas:
z = (i[55:57])
if (z != «»):
z = float(z)
p = p + z
conthigh = conthigh + 1
high = p // conthigh
print(‘The average gas mileage in highway is: ‘,high)
f = 0
contmind = 0
for i in lineas:
a = (i[42:46])
if (a != «»):
a = float(a)
f = f + a
contmind = contmind + 1
mind = y//contmind
print(‘The average mind-range price is: ‘,mind)
#52
Comentarios recientes