Isoraqathedh

Currency To Time converter

Jul 9th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import easygui
  2.  
  3. winTitle = "Dollar To Time Converter"
  4. convUnitsUp = (46, 5, 182/5, 1000, 1000, 65, 540/65, 4567/540, 3)
  5. unitNames = ("minute(s)", "day(s)", "week(s)", "year(s)", "millenium/a", "million year(s)", "Cretacean(s)", "Cambria(s)", "Earth(s)", "Universe(s)")
  6. oneK = "000"
  7. divisors = (("k", oneK), ("M", oneK * 2), ("G", oneK * 3), ("T", oneK * 4))
  8. finalString = ""
  9. #  $ 1          = 1 min
  10. #   46 mins     = 1 day
  11. #    5 days     = 1 week
  12. #  182 days     = 1 year
  13. # 1000 years    = 1 millenium
  14. # 1000 millenia = 1 ice age
  15. #   65 ice ages = 1 Cretaceous
  16. #  540 ice ages = 1 Cambrian
  17. # 4567 ice ages = 1 Earth
  18. #    3 Earths   = 1 Universe
  19. currencyUnit = [-1, -1]
  20. while currencyUnit[0] == -1 and currencyUnit[1] == -1:
  21.     inValue = easygui.enterbox("Enter a dollar amount, followed by USD or HKD", winTitle)
  22.     currencyUnit = [inValue.find("USD"), inValue.find("HKD")]
  23.     for i in divisors:
  24.         inValue = inValue.replace(i[0], i[1])
  25.     # In any case, parse integer (or just crop off the USD/HKD!)
  26.     print("converting {0}".format(inValue))
  27.     currencyValue = int(inValue[:-4])
  28.     print(currencyValue)
  29.     if not currencyUnit[0] == -1:
  30.         # if USD, divide by 7.8
  31.         currencyValue = currencyValue * 7.8
  32.         break
  33.     elif not currencyUnit[1] == -1:
  34.         break
  35. j = 0
  36. for i in convUnitsUp:
  37.     currencyValue = currencyValue / i
  38.     if currencyValue < 1:
  39.         currencyValue = currencyValue * i
  40.         break
  41.     j = j+1
  42. finalString = "That amount of money will buy lunch for {0} {1}.".format(round(currencyValue, 3), unitNames[j])
  43. easygui.msgbox(finalString, winTitle)
Advertisement
Add Comment
Please, Sign In to add comment