Python Currency Converter
Hey Guys,
Today we will learn how to make a simple currency converter.
I will be sharing the code before explaining.
So, here is the code down below:
def Convertor():
#Currency Convertor.
import time
print("Welcome to the Currency Converter.")
time.sleep(1)
print("Enter your Currency and number to Convert down below.")
time.sleep(1)
print("""Note: 1)This can convert only within Dollars,Rupees,Pounds and Euros.
More currency to convert will be coming later.
2)Currency values are subject to change in real life,but not here. They tend to stay the same, so please don't
use this for commercial purposes""")
time.sleep(1)
currency = input("Enter the Currency that is to be Converted(Rupees,Dollars,Euros,Pounds): ")
time.sleep(1)
Currency = input("Enter the Currency that is the Final Currency: ")
Money_value = float(input("Enter the Money value : "))
#Money Value = input("Enter the Money value to given: ")
#Convertor for Rupees
if currency.upper() == "RUPEES" and Currency.upper() == "DOLLARS":
print("The Money is ",Money_value*0.013,"Dollars")
elif currency.upper() == "RUPEES" and Currency.upper() == "POUNDS":
print("The Money is ",Money_value*0.010,"Pounds")
elif currency.upper() == "RUPEES" and Currency.upper() == "EUROS":
print("The Money is ",Money_value*0.012,"Euros")
elif currency.upper() == "RUPEES" and Currency.upper() == "RUPEES":
print("The Money is ",Money_value*1,"Rupees")
#Convertor for Dollars
elif currency.upper() == "DOLLARS" and Currency.upper() == "POUNDS":
print("The Money is ",Money_value*0.74,"Pounds")
elif currency.upper() == "DOLLARS" and Currency.upper() == "EUROS":
print("The Money is ",Money_value*0.88,"Euros")
elif currency.upper() == "DOLLARS" and Currency.upper() == "RUPEES":
print("The Money is ",Money_value*74.33,"Rupees")
elif currency.upper() == "Dollars" and Currency.upper() == "Dollars":
print("The Money is ",Money_value*1,"Dollars")
#Convertor for Euros
elif currency.upper() == "EUROS" and Currency.upper() == "DOLLARS":
print("The Money is ",Money_value*1.13,"Dollars")
elif currency.upper() == "EUROS" and Currency.upper() == "RUPEES":
print("The Money is ",Money_value*84.27,"Rupees")
elif currency.upper() == "EUROS" and Currency.upper() == "POUNDS":
print("The Money is ",Money_value*0.84,"Pounds")
elif currency.upper() == "EUROS" and Currency.upper() == "EUROS":
print("The Money is ",Money_value*1,"Euros")
#Convertor for Pounds
elif currency.upper() == "POUNDS" and Currency.upper() == "DOLLARS":
print("The Money is ",Money_value*1.35,"Dollars")
elif currency.upper() == "POUNDS" and Currency.upper() == "EUROS":
print("The Money is ",Money_value*1.19,"Euros")
elif currency.upper() == "POUNDS" and Currency.upper() == "RUPEES":
print("The Money is ",Money_value*100.46,"Rupees")
elif currency.upper() == "POUNDS" and Currency.upper() == "POUNDS":
print("The Money is ",Money_value*1,"Pounds")
else:
print("That's not appropriate.")
Convertor()
Again = input("Do you want to Convert the Currencies again? (y/n): ")
if Again.lower() == 'y':
print(Convertor())
elif Again.lower() == 'n':
print("Hope you enjoyed the Currency Convertor.")
else:
print("That's not appropriate.")
This currency calculator repeats the work if entered yes again after finishing the work. We have added functions to do that.
Steps to explain:
1.We have Coded the basic things that we need like the currency, value and welcoming statements.
2.We have created a if statement to make python convert a specific currency to another and what to do if something else is entered. I have used the current value of the currency converted. It may change but you can change it and use it as you wish.
3.Next we have created a Again input statement to ask if the user wants to convert again or not, and if yes it displays the whole thing again. To keep it short we have created a function and just wrote 'Game()' the functions name.
4. It also displays something if other than the required answer something is entered.
5. The 'Variable_name.upper() or Variable_name.lower()' changes the input that the user entered to upper or lower case and checks the condition.
I have explained in 5 simple steps.
Meet you on the next project and post, Until then Bye!
Be sure to Share this blog to at least with 15 members you know
By the Blog author.
2 Comments
Hope you Like this!
ReplyDeletePlease report to me if the code is too small
ReplyDelete