Nov 10, 2013 08:39 AM
(This post was last modified: Nov 10, 2013 11:31 AM by XBatt.)
Here is a currency converter I made, I know it's not very efficient and there are other ways to make this better. Please provide suggestions, also what does the "def" do in python?
Thanks
PHP Code
<?php
#CURRENT EXCHANGE RATES
pound = 1.00
euro = 1.19
dollar = 1.60
yen = 158.33
#CURRENT EXCHANGE RATES
print ("Welcome to my Currency Converter")
print ("==")
print ("The current exchange rates are:")
print ("\n£1 = $1.60")
print ("\n£1 = €1.19")
print ("\n£1 = ¥158.33")
ccinput = input("If you would like to change the currency please enter 1\nIf you would like to do a currency conversion enter 2\nIf you would like to print a text file with the current exchange rates enter 3\nYour selection:")
if ccinput == ("1"):
print ("You have choosen too change the exchange rates")
print ("This is currently in progress")
elif ccinput == ("2"):
print ("\n==")
print ("You have choosen to convert a currency")
print ("==")
currencychoice = input("Please choose which currency to exchange, pound, euro, dollar or yen?\nYour selection:")
##
if currencychoice == ("pound"):
poundselect1 = input ("What currency would you like to exchange your pound to?:")
if poundselect1 == ("euro"):
poundeuroselect = input("You have choosen to exchange pound to euro, how many pounds would you like to exchange to euro?")
intconvert1 = int(poundeuroselect)
print (intconvert1*euro)
elif poundselect1 == ("dollar"):
pounddollarselect = input("You have choosen to exchange pound to dollar, how many pounds would you like to exchange to dollar?")
intconvert2 = int(pounddollarselect)
print (intconvert2*dollar)
elif poundselect1 == ("yen"):
poundyenselect = input("You have choosen to exchange pound to yen, how many pounds would you like to exchange to yen?")
intconvert3 = int(poundyenselect)
print (intconvert3*yen)
else:
print ("FAIL, please try again.")
else:
1 + 1
##
if currencychoice == ("euro"):
euroselect1 = input ("What currency would you like to exchange your euro to?:")
if euroselect1 == ("pound"):
europoundselect = input("You have choosen to exchange euro to pound, how many pounds would you like to exchange to euro?")
intconvert4 = int(europoundselect)
print (intconvert4*0.84)
elif euroselect1 == ("dollar"):
eurodollarselect = input("You have choosen to exchange pound to dollar, how many pounds would you like to exchange to dollar?")
intconvert5 = int(eurodollarselect)
print (intconvert2*dollar)
elif euroselect1 == ("yen"):
euroyenselect = input("You have choosen to exchange pound to yen, how many pounds would you like to exchange to yen?")
intconvert6 = int(euroyenselect)
print (intconvert6*yen)
else:
print ("FAIL, please try again.")
else:
1 + 1
##
if currencychoice == ("dollar"):
dollarselect1 = input ("What currency would you like to exchange your dollar to?:")
if dollarselect1 == ("pound"):
dollarpoundselect = input("You have choosen to exchange euro to pound, how many pounds would you like to exchange to euro?")
intconvert7 = int(dollarpoundselect)
print (intconvert7*0.62)
elif dollarselect1 == ("euro"):
dollareuroselect = input("You have choosen to exchange pound to dollar, how many pounds would you like to exchange to dollar?")
intconvert8 = int(dollareuroselect)
print (intconvert8*euro)
elif dollarselect1 == ("yen"):
dollaryenselect = input("You have choosen to exchange pound to yen, how many pounds would you like to exchange to yen?")
intconvert9 = int(dollaryenselect)
print (intconvert9*yen)
else:
print ("FAIL, please try again.")
else:
1 + 1
elif ccinput == ("3"):
text_file = open("current_exchange_rates.txt", "w")
text_file.write("£1 = $1.60 \n")
text_file.write("£1 = €1.19 \n")
text_file.write("£1 = ¥158.33\n")
text_file.close()
print("The text file has been created in the directory of this script!")
else:
print ("Sorry you have crashed the program please restart :P")
input("...Please press enter to close:...")
Thanks
Things I love - Pentesting,Python,Linux,CryptoCurrencies,Legion,Server Administration,Raspberry Pi - PM me if you wanna talk!
Freelance Pentester and Python coder.
![[Image: 2EOBWgX.png]](https://i.imgur.com/2EOBWgX.png)
Freelance Pentester and Python coder.
![[Image: 2EOBWgX.png]](https://i.imgur.com/2EOBWgX.png)

