python - unorderable types: float() <= lists() -
i cant code compare 2 numbers want see if number smaller if want print "is smaller" if not want end. lat.csv fill of numbers 52.6169933 , user input similar.
import csv lat = float(input("enter location latitude")) lat = lat - 0.01862 x = 1 open('lat.csv') f: reader = csv.reader(f) arraylat = list(reader) if float(lat) <= arraylat[x]: print("is smaller") print("end") traceback (most recent call last): file "c:/users/ryan/documents/python/map/test.py", line 8, in <module> if float(lat) <= arraylat[x]: typeerror: unorderable types: float() <= list()
i see couple of issues example code put up, should able fix if go through python tutorial beginners. assuming understand problem,
with open('lat.csv') f: reader = csv.reader(f) row in reader: row = row.split(',') is_smaller = false val in row: if(lat <= float(val)): print("is smaller") is_smaller = true break if is_smaller == true: break print("end")
the is_smaller flag check if value larger input found, , if is, stops searching , prints "is smaller" helpful read on csv.
Comments
Post a Comment