Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.39 KB | None | 0 0
  1. """TASK:
  2. You are currently in the United States of America.
  3. The main currency here is known as the United States Dollar (USD).
  4. You are planning to travel to another country for vacation, so you make
  5. it today's goal to convert your USD (all bills, no cents) into the appropriate currency.
  6. This will help you be more prepared for when you arrive in the country you will be vacationing in.
  7.  
  8. Given an integer (usd) representing the amount of dollars you have and a string (currency)
  9. representing the name of the currency used in another country,
  10. it is your task to determine the amount of foreign currency you will
  11. receive when you exchange your United States Dollars.
  12.  
  13. However, there is one minor issue to deal with first.
  14. The screens and monitors at the Exchange are messed up.
  15. Some conversion rates are correctly presented, but other
  16. conversion rates are incorrectly presented. For some countries,
  17. they are temporarily displaying the standard conversion
  18. rate in the form of a number's binary representation!
  19.  
  20. You make some observations. If a country's currency begins with a vowel,
  21. then the conversion rate is unaffected by the technical difficulties.
  22. If a country's currency begins with a consonant,
  23. then the conversion rate has been tampered with.
  24.  
  25. Normally, the display would show 1 USD converting to 111 Japanese Yen.
  26. Instead, the display is showing 1 USD converts to 1101111 Japanese Yen.
  27. You take it upon yourself to sort this out.
  28. By doing so, your 250 USD rightfully becomes 27750 Japanese Yen.
  29.  
  30. function(250, "Japanese Yen") => "You now have 27750 of Japanese Yen."
  31.  
  32. Normally, the display would show 1 USD converting to 21 Czech Koruna.
  33. Instead, the display is showing 1 USD converts to 10101 Czech Koruna.
  34. You take it upon yourself to sort this out.
  35. By doing so, your 325 USD rightfully becomes 6825 Czech Koruna.
  36.  
  37. function(325, "Czech Koruna") => "You now have 6825 of Czech Koruna."
  38.  
  39. Using your understanding of converting currencies in conjunction
  40. with the preloaded code shown below, properly convert your
  41. dollars into the correct amount of foreign currency."""
  42.  
  43. # Pre loaded dictionary:
  44. CONVERSION_RATES = {
  45.   "Argentinian Peso": 10,
  46.   "Armenian Dram": 478,
  47.   "Bangladeshi Taka": 1010010,
  48.   "Croatian Kuna": 110,
  49.   "Czech Koruna": 10101,
  50.   "Dominican Peso": 110000,
  51.   "Egyptian Pound": 18,
  52.   "Guatemalan Quetzal": 111,
  53.   "Haitian Gourde": 1000000,
  54.   "Indian Rupee": 63,
  55.   "Japanese Yen": 1101111,
  56.   "Kenyan Shilling": 1100110,
  57.   "Nicaraguan Cordoba": 11111,
  58.   "Norwegian Krone": 1000,
  59.   "Philippine Piso": 110010,
  60.   "Romanian Leu": 100,
  61.   "Samoan Tala": 11,
  62.   "South Korean Won": 10000100011,
  63.   "Thai Baht": 100000,
  64.   "Uzbekistani Som": 8333,
  65.   "Venezuelan Bolivar": 1010,
  66.   "Vietnamese Dong": 101100000101101
  67. }
  68.  
  69. # Function solving the task:
  70. def convert_my_dollars(usd="", currency=""):
  71.     # Updating dictionary with correct values
  72.     for k, v in CONVERSION_RATES.items():
  73.         binary = True
  74.         for j in v:
  75.             if j != "0" or j!= "1":
  76.                 binary= False
  77.         if binary:
  78.             CONVERSION_RATES[k] = int(str(v), 2)
  79.  
  80.     # Fetching conversion rate
  81.     conversion = CONVERSION_RATES.get(currency)
  82.     # Converting currency
  83.     converted_cur = int(usd * conversion)
  84.  
  85.     # Creating end statement
  86.     statement = "You now have " + str(converted_cur) + " of " + currency + "."
  87.     return statement
  88.  
  89. #TESTS:
  90. Test.describe("Example Test Cases")
  91. Test.assert_equals(convert_my_dollars(7, "Armenian Dram"), "You now have 3346 of Armenian Dram.")
  92. Test.assert_equals(convert_my_dollars(322, "Armenian Dram"), "You now have 153916 of Armenian Dram.")
  93. Test.assert_equals(convert_my_dollars(25, "Bangladeshi Taka"), "You now have 2050 of Bangladeshi Taka.")
  94. Test.assert_equals(convert_my_dollars(730, "Bangladeshi Taka"), "You now have 59860 of Bangladeshi Taka.")
  95. Test.assert_equals(convert_my_dollars(37, "Croatian Kuna"), "You now have 222 of Croatian Kuna.")
  96. Test.assert_equals(convert_my_dollars(40, "Croatian Kuna"), "You now have 240 of Croatian Kuna.")
  97. Test.assert_equals(convert_my_dollars(197, "Czech Koruna"), "You now have 4137 of Czech Koruna.")
  98. Test.assert_equals(convert_my_dollars(333, "Czech Koruna"), "You now have 6993 of Czech Koruna.")
  99. Test.assert_equals(convert_my_dollars(768, "Dominican Peso"), "You now have 36864 of Dominican Peso.")
  100. Test.assert_equals(convert_my_dollars(983, "Dominican Peso"), "You now have 47184 of Dominican Peso.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement