Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import easygui
- import csv
- winTitle = "Dollar To Time Converter"
- convUnitsUp = (46, 5, 182/5, 1000, 1000, 65, 540/65, 4567/540, 3)
- unitNames = ("minute(s)", "day(s)", "week(s)", "year(s)", "millenium/a", "million year(s)", "Cretacean(s)", "Cambria(s)", "Earth(s)", "Universe(s)")
- oneK = "000"
- divisors = (("k", oneK), ("M", oneK * 2), ("G", oneK * 3), ("T", oneK * 4))
- finalString = ""
- displayFactoid = False
- millionYearsValue = 0
- # $ 1 = 1 min
- # 46 mins = 1 day
- # 5 days = 1 week
- # 182 days = 1 year
- # 1000 years = 1 millenium
- # 1000 millenia = 1 ice age
- # 65 ice ages = 1 Cretaceous
- # 540 ice ages = 1 Cambrian
- # 4567 ice ages = 1 Earth
- # 3 Earths = 1 Universe
- currencyUnit = [-1, -1]
- while currencyUnit[0] == -1 and currencyUnit[1] == -1:
- inValue = easygui.enterbox("Enter a dollar amount, followed by USD or HKD", winTitle)
- currencyUnit = [inValue.find("USD"), inValue.find("HKD")]
- for i in divisors:
- inValue = inValue.replace(i[0], i[1])
- # to do: don't be lazy and actually multiply the dang thing.
- # In any case, parse integer (or just crop off the USD/HKD!)
- currencyValue = int(inValue[:-4])
- if not currencyUnit[0] == -1:
- # if USD, divide by 7.8
- currencyValue = currencyValue * 7.8
- break
- elif not currencyUnit[1] == -1:
- break
- j = 0
- print(" {0} {1}".format(round(currencyValue, 3), unitNames[0]))
- for i in convUnitsUp:
- currencyValue = currencyValue / i
- print("= {0} {1}".format(round(currencyValue, 3), unitNames[j+1]))
- if currencyValue < 1:
- currencyValue = currencyValue * i
- break
- j = j+1
- if j == 5:
- displayFactoid = True
- millionYearsValue = currencyValue
- if displayFactoid:
- with open('lunchValues.csv', 'r', newline='') as dataFile:
- timeReader = csv.reader(dataFile)
- provisionalProperties = ["", ""]
- for row in timeReader:
- if int(row[0]) > millionYearsValue:
- break
- else:
- provisionalProperties = [row[1], row[2]]
- descrString = "; it was the {0} then, and back then {1}".format(provisionalProperties[0], provisionalProperties[1])
- else:
- descrString = "."
- finalString = "That amount of money will buy lunch for {0} {1}{2}".format(round(currencyValue, 3), unitNames[j], descrString)
- easygui.msgbox(finalString, winTitle)
Advertisement
Add Comment
Please, Sign In to add comment