lundi 29 août 2016

IF statement picking first option in currency converter (python)

print "Pound Sterling converter"
print "You can convert pounds to either dollars, euros or yen"

print

dollar = 0
euro = 0
yen = 0

convert_to = input ("What currency do you want to convert to? ")
amount = input("How much would you like to convert? ")

print

if convert_to == dollar:
    amount = amount * 1.3
elif convert_to == euro:
     amount = amount * 1.17
elif convert_to == yen:
    amount = amount * 133.66
else:
    print "You must pick either dollar, euro or yen."

print amount

I'm a beginner in Python, as you can probably tell. All I want this program to do is have the user choose a currency (convert_to) and then choose how much they want to convert (amount) and then the program will convert it for them.

When I run the program, the if statement does not work correctly. Instead of seeing what convert_to is, it goes through the convert_to == dollar part regardless of if you type euro or yen. The numbers they are being multiplied by are simply the conversion rates from pounds.

also, a side note but less important one, the final else part does not work. The program brings up a "input not defined" error instead of printing "You must pick either dollar, euro or yen."

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire