Advertisement
Guest User

Lab 2

a guest
Sep 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/usr/binpython2.7
  2.  
  3.  
  4. openFile = file('units.csv', 'r')
  5. lines = openFile.readlines()
  6.  
  7. header = lines[0]
  8.  
  9. unitFrom=[]
  10. unitTo=[]
  11. valuetobeconverted=[]
  12. unitType = []
  13.  
  14. for line in lines [1:]:
  15. data=line.strip().split(',')
  16.  
  17. #unit type list
  18. for line in lines [1:]:
  19. data=line.strip().split(',')
  20. if data[3] not in unitType:
  21. unitType.append(data[3])
  22. print unitType
  23. unittype = raw_input("what unit type would you like to convert")
  24.  
  25. #unit from list
  26. for line in lines [1:]:
  27. data=line.strip().split(',')
  28. if data[0] not in unitFrom and unittype == data[3]:
  29. unitFrom.append(data[0])
  30. print unitFrom
  31. unitfrom =raw_input(" Enter Unit From from list: ")
  32.  
  33. #unit to list
  34. for line in lines [1:]:
  35. data=line.strip().split(',')
  36. if data[1] not in unitTo and unittype == data[3]:
  37. unitTo.append(data[0])
  38. print unitTo
  39. unitto=raw_input("Enter Unit to from list:")
  40.  
  41.  
  42. valuetobeconverted=raw_input('Enter numeric value to be converted')
  43.  
  44. for line in lines [1:]:
  45. data=line.strip().split(',')
  46. if unitfrom == data[0] and unitto == data[1] and unittype != "temperature":
  47. valueconverted= float(valuetobeconverted)*float(data[2])
  48. print valueconverted, unitto
  49. elif unittype == "temperature" and unitfrom==data[0] and unitto ==data[1]:
  50. valueconverted=(float(valuetobeconverted)*float(data[2]))+float(data[4])
  51. print valueconverted, unitto
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement