0

Can someone help with my python code?

EUR = 1 USD = 1.13798 GBP = 0.857679 RUB = 74.9470 def currencyConverter(): chosenCurrency = input("Do you wish to convert your euros to \n1)USD \n2)RUB \n3)GBP\n------------------------------------\n") print (chosenCurrency, "\n------------------------------------\n") #USD if (chosenCurrency) == "1" eurAmount = input("How many euros do you wish to convert into USD?\n------------------------------------") print((eurAmount) * 1.13798) #RUB elif (chosenCurrency) == "2" eurAmount = input("How many euros do you wish to convert into RUB?\n------------------------------------") print((eurAmount) * 74.9470) #GBP elif (chosenCurrency) == "3" eurAmount = input("How many euros do you wish to convert into GBP?\n------------------------------------") print((eurAmount) * 0.857679) #Error else print ("Error, please try again. Enter 1, 2 or 3") currencyConverter() https://code.sololearn.com/cBEH23DcmATx/#py

28th Feb 2019, 7:26 PM
Ville Nordström
Ville Nordström - avatar
21 Respuestas
+ 1
CR34TUR3, your code: 12. if (chosenCurrency) == "1": 13. eurAmount = float(input("How many euros do you wish to convert into USD?\n------------------------------------")) 14. print((eurAmount) * 1.13798) debug: 12. if (chosenCurrency) == "1": 13. eurAmount = float(input("How many euros do you wish to convert into USD?\n------------------------------------")) 14. print((eurAmount) * 1.13798) You are advised: "watch for indents".😕 Line 14, no indent.
28th Feb 2019, 8:27 PM
Solo
Solo - avatar
+ 3
CR34TUR3 It remains only for you to rewrite the code ☺: https://code.sololearn.com/c3sMRuGJnem3/?ref=app
28th Feb 2019, 8:14 PM
Solo
Solo - avatar
+ 3
Hey, you wanna check out my new version? It would've not been possible without you two xd https://code.sololearn.com/caeXrTEd10z8/#py
2nd Mar 2019, 10:08 AM
Ville Nordström
Ville Nordström - avatar
+ 2
else: print("Error...") eurAmount = float(input("How many euros...")) Use colons ":" at the end of the if and elif statements.
28th Feb 2019, 7:28 PM
Diego
Diego - avatar
+ 2
and don't forget the indentations..
28th Feb 2019, 7:54 PM
Ali
Ali - avatar
+ 2
You could move you currency amounts inside the function as variables and then reference them instead of hard coding the same info in the if, elif and else statements
28th Feb 2019, 9:33 PM
Mike Knott
Mike Knott - avatar
+ 1
Remember to use indentation. if chosenCurrency == "1: eurAmount = ... And fix the else statement. else: print("Error...")
28th Feb 2019, 7:52 PM
Diego
Diego - avatar
+ 1
Omg...i never checked the print lines carefully enough...like i indented them(dunno if that's english lol) but i didn't indent them again after i edited the other lines of code. Vasiliy and Diego...thank you so much for helping me to finish my first python program ever! I will keep improving this as i learn more and i will keep learning. Thank you both :)
28th Feb 2019, 8:48 PM
Ville Nordström
Ville Nordström - avatar
+ 1
CR34TUR3 😓👏👏👏
28th Feb 2019, 8:53 PM
Solo
Solo - avatar
+ 1
CR34TUR3 It remains to remove the extra digits after the decimal point. This is done like this: "print(round(int(eurAmount) * 1.13798, 2))". See my code. And do not forget to specify the date of exchange rates.
28th Feb 2019, 9:06 PM
Solo
Solo - avatar
+ 1
Your doing great so far 👍 and here is how to do the above https://code.sololearn.com/czMhryqmncIP/?ref=app
28th Feb 2019, 9:48 PM
Mike Knott
Mike Knott - avatar
0
I saved it. Did i miss your point or why doesn't it work?
28th Feb 2019, 7:35 PM
Ville Nordström
Ville Nordström - avatar
0
And i thought i was getting better...updated again. And sorry for wasting your time, didn't get it to work this time either :(
28th Feb 2019, 7:49 PM
Ville Nordström
Ville Nordström - avatar
0
Okay i'll just give up at this point...i just don't get it :'( Like i do everything you tell me to do and there is always a new syntax error..
28th Feb 2019, 8:08 PM
Ville Nordström
Ville Nordström - avatar
0
But...i see like no difference at all...i use the indentations like what am i doing wrong at this point? People say that this is a really basic level of python and i can't even understand that
28th Feb 2019, 8:21 PM
Ville Nordström
Ville Nordström - avatar
0
CR34TUR3 Hope to see more from you in the future. Happy coding!
28th Feb 2019, 8:52 PM
Diego
Diego - avatar
0
Same to you :)
28th Feb 2019, 8:53 PM
Ville Nordström
Ville Nordström - avatar
0
Yeah : ) I will also change it so i can convert RUB into USD and USD into GBP and so on : ) And i'll also probably add more currencies later. And if i can find a way to connect it to online so the values stay accurate etc. Isn't optimizing and improving existing code good practice too?
28th Feb 2019, 9:08 PM
Ville Nordström
Ville Nordström - avatar
0
I have yet to find out how that works. If you check the "learn python3"...i just got to the "functions and modules".
28th Feb 2019, 9:35 PM
Ville Nordström
Ville Nordström - avatar