Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/binpython2.7
- openFile = file('units.csv', 'r')
- lines = openFile.readlines()
- header = lines[0]
- unitFrom=[]
- unitTo=[]
- valuetobeconverted=[]
- unitType = []
- for line in lines [1:]:
- data=line.strip().split(',')
- #unit type list
- for line in lines [1:]:
- data=line.strip().split(',')
- if data[3] not in unitType:
- unitType.append(data[3])
- print unitType
- unittype = raw_input("what unit type would you like to convert")
- #unit from list
- for line in lines [1:]:
- data=line.strip().split(',')
- if data[0] not in unitFrom and unittype == data[3]:
- unitFrom.append(data[0])
- print unitFrom
- unitfrom =raw_input(" Enter Unit From from list: ")
- #unit to list
- for line in lines [1:]:
- data=line.strip().split(',')
- if data[1] not in unitTo and unittype == data[3]:
- unitTo.append(data[0])
- print unitTo
- unitto=raw_input("Enter Unit to from list:")
- valuetobeconverted=raw_input('Enter numeric value to be converted')
- for line in lines [1:]:
- data=line.strip().split(',')
- if unitfrom == data[0] and unitto == data[1] and unittype != "temperature":
- valueconverted= float(valuetobeconverted)*float(data[2])
- print valueconverted, unitto
- elif unittype == "temperature" and unitfrom==data[0] and unitto ==data[1]:
- valueconverted=(float(valuetobeconverted)*float(data[2]))+float(data[4])
- print valueconverted, unitto
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement