Please, is anyone here familiar with Python Version 3.4.1? @ Anyone at all who can help me, please help, my assignment is due in 4 hours 30 minutes and ive been stuck witht he same problem for 4 days already
My code so far ``` print('1. Argentine Peso') print('2. Brazilian Real') print('3. British Pound') print('4. European Euro') print('5. Indian Rupee') print('6. Japanese Yen') print('7. Russian Ruble') print('8. Other \n') usd = 0 print('-----------------------------------------------------------') usd = eval(input('Enter amount to convert (=< 0 to exit): ')) peso = usd * 8.48 real = usd * 2.46 pound = usd * 0.62 euro = usd * 0.79 rupee = usd * 61.59 yen = usd * 109.49 ruble = usd * 39.45 num = 0 num = eval(input('Enter Selection: ')) while num > 0: num = num + 1 if num == 1: print('' + str(usd) + ' US Dollars converts to: ' + str(round(peso,2)) + ' Argentine Pesos.') elif num == 2: print('' + str(usd) + ' US Dollars converts to: ' + str(round(real,2)) + ' Brazilian Real.') elif num == 3: print('' + str(usd) + ' US Dollars converts to: ' + str(round(pound,2)) + ' British Pound.') elif num == 4: print('' + str(usd) + ' US Dollars converts to: ' + str(round(euro,2)) + ' European Euro.') elif num == 5: print('' + str(usd) + ' US Dollars converts to: ' + str(round(rupee,2)) + ' Indian Rupee.') elif num == 6: print('' + str(usd) + ' US Dollars converts to: ' + str(round(yen,2)) + ' Japanese Yen.') elif num == 7: print('' + str(usd) + ' US Dollars converts to: ' + str(ruble) + ' Russian Ruble.') elif num == 8: currency = input('Enter current to convert to: ') amount = eval(input('Enter the conversion factor for ' + currency + ': ')) random = usd * amount print('' + str(usd) + ' US Dollars converts to: ' + str(random) + ' ' + currency + '.') else: print('-----------------------------------------------------------') #mark of starting over eval(input('Enter amount to convert (=<0 to exit): ')) num = eval(input('Enter selection: ')) ```
It works pretty well so far but right now it after you select a number 1-8, it adds 1 to your selection and prnts all after that one. Example: Selection is 4, the program runs selection #s 5,6,7,8 and restarts the program
@e.mccormick hey so i know ive already asked for you to help with this exact problem but i still cant figure out what the problem is. any chance you would be willing to help again :\
Well, you are adding to the num... =/
someone told me that my problem has to do with using ``` num=num+1 ``` i tried many things but idk, i need it because its the only thing i could find to do to fix the infinite loop problem i had before
Well, are you trying to offer the person a chance to convert again, or to a different ammount of money?
yes im trying to allow the user to choose one conversion after entering an amount for usd, then after that one conversion it should ask for a new value for usd and allow them to pick a new conversion option.
Then put the user input inside the loop and also tell them to put in 0 to exit.
This is my actualy assignment instruction paper if you wanna look quick
Your loop is also evaluation on the wrong value.
what do you mean by that?
'while num > 0:' Instructions: Write a program to continually ask the user for a US dollar amount to be converted to a monetary value in some other currency. Terminate the program when the user enters zero(0) or a negative value. num is not the monetary value.
usd is the monetary value?
Yes. USD is the monitary value Also, think about this: ``` flag = true while flag: if input <= 0: flag = false other stuff ``` That is one possible solution. Or doing if and a break/continue and testing on usd > 0.
A do-while loop is another possibility because that does stuff at least once.
yeah another person suggested the do-while loop but i dont believe we learned about those just yet
as far as loops go, we learned while and for loops
but only the basic while loop
They have it end right after the curency is set to 0, so you need to use an if-break construct.
if i put the piece where user inputs usd value and makes a selection, inside the while loop, all it prints are #1-8 selections and program ends
You just need to make it true before they input the amount. You made it false.
Also, watch out for where your calculations happen.
``` peso = usd * 8.48 real = usd * 2.46 pound = usd * 0.62 euro = usd * 0.79 rupee = usd * 61.59 yen = usd * 109.49 ruble = usd * 39.45 ``` should this be inside the while?
Yep. You need to recalculate after a new value it taken in and before the print of the new output.
alright so i think its working, is my else statement at the bottom just totally pointless?
No. It is incorrect, but not pointless. You would use an else there for an error message if they entered an invalid type of currency.
ooooh so its correct but i should make it print something else.
i think ill just remove it, an error message isnt required for this and i dont need to complicate things at this point lol
It is good to have an else as a catch all. No need to have any input. Just output for "What where you thinking!"
oh so its that easy, alright
See any problems? ``` print('1. Argentine Peso') print('2. Brazilian Real') print('3. British Pound') print('4. European Euro') print('5. Indian Rupee') print('6. Japanese Yen') print('7. Russian Ruble') print('8. Other \n') usd = 0 usd = eval(input('Enter amount to convert (=< 0 to exit): ')) while usd > 0: peso = usd * 8.48 real = usd * 2.46 pound = usd * 0.62 euro = usd * 0.79 rupee = usd * 61.59 yen = usd * 109.49 ruble = usd * 39.45 num = 0 num = eval(input('Enter Selection: ')) if num == 1: print('' + str(usd) + ' US Dollars converts to: ' + str(round(peso,2)) + ' Argentine Pesos.') elif num == 2: print('' + str(usd) + ' US Dollars converts to: ' + str(round(real,2)) + ' Brazilian Real.') elif num == 3: print('' + str(usd) + ' US Dollars converts to: ' + str(round(pound,2)) + ' British Pound.') elif num == 4: print('' + str(usd) + ' US Dollars converts to: ' + str(round(euro,2)) + ' European Euro.') elif num == 5: print('' + str(usd) + ' US Dollars converts to: ' + str(round(rupee,2)) + ' Indian Rupee.') elif num == 6: print('' + str(usd) + ' US Dollars converts to: ' + str(round(yen,2)) + ' Japanese Yen.') elif num == 7: print('' + str(usd) + ' US Dollars converts to: ' + str(ruble) + ' Russian Ruble.') elif num == 8: currency = input('Enter current to convert to: ') amount = eval(input('Enter the conversion factor for ' + currency + ': ')) random = usd * amount print('' + str(usd) + ' US Dollars converts to: ' + str(random) + ' ' + currency + '.') else: print('What were you thinking!') ```
ive tested each selection and seems to work
Well, might want a nice one like, "That is not a valid currency selection" but it works. Try it for like 9 or 42. See, that is where the else is handy.
Calculate after getting the new ... ummm... you still do not have it looping validly.
Try and get it to do the same output as in the examples.
alright
i tried to put the usd part inside the loop and it gives me an error or it just prints out the option list
Just as a psudocode example: ``` a = 1 while a > 0 input a if a <= 0 exit loop input b print a + b ``` Because I set a to a true value, I got into the loop fine. I never actually use this value because I instantly replace it with user input. Then to make sure I have a catch to kill things, I do an if right after I get a.
so 'a' is my 'usd' correct?
sorry ik we already went over this part, just clarrifying
``` print('1. Argentine Peso') print('2. Brazilian Real') print('3. British Pound') print('4. European Euro') print('5. Indian Rupee') print('6. Japanese Yen') print('7. Russian Ruble') print('8. Other \n') usd = 1 while usd > 0: usd = eval(input('Enter amount to convert (less than 0 to exit): ')) if usd <= 0: #used to exit if a negative number or 0 is entered. exit peso = usd * 8.48 real = usd * 2.46 pound = usd * 0.62 euro = usd * 0.79 rupee = usd * 61.59 yen = usd * 109.49 ruble = usd * 39.45 num = 0 num = eval(input('Enter Selection: ')) if num == 1: print('' + str(usd) + ' US Dollars converts to: ' + str(round(peso,2)) + ' Argentine Pesos.\n') elif num == 2: print('' + str(usd) + ' US Dollars converts to: ' + str(round(real,2)) + ' Brazilian Real.\n') elif num == 3: print('' + str(usd) + ' US Dollars converts to: ' + str(round(pound,2)) + ' British Pound.\n') elif num == 4: print('' + str(usd) + ' US Dollars converts to: ' + str(round(euro,2)) + ' European Euro.\n') elif num == 5: print('' + str(usd) + ' US Dollars converts to: ' + str(round(rupee,2)) + ' Indian Rupee.\n') elif num == 6: print('' + str(usd) + ' US Dollars converts to: ' + str(round(yen,2)) + ' Japanese Yen.\n') elif num == 7: print('' + str(usd) + ' US Dollars converts to: ' + str(ruble) + ' Russian Ruble.\n') elif num == 8: currency = input('Enter current to convert to: ') amount = eval(input('Enter the conversion factor for ' + currency + ': ')) random = usd * amount print('' + str(usd) + ' US Dollars converts to: ' + str(random) + ' ' + currency + '.\n') else: print('Invalid input! Please try again.\n') ``` idk why it all turned red but i think this is what your meaning by your example
In your case, yes. See how that keeps it from falling out of the loop?
i never knew we had an 'exit' idk what its called, a function or something?
Well, exit is not how to stop a loop. Did your book/class talk about how to skip or exit loops?
no we never really went over that
oh nvm that doesnt even make it exit, forgot to test it.
ill have to read into that part
ahh so 'break' makes it exit, see we had that in c++ i hadnt thought to try that on here. i took a c++ class a few years back in high school.
hm it exits for zero but not a negative number
Odd...
when i put a negative number it refers to the else and says invalid input and restarts
Did you do == 0 or <= 0? Did you put the negative as the currency type or as the money?
<= 0
the currency type
lol alright i see where your going
the exit is if the usd = 0 or negative, so i have to do for the money not type
So, was it when you tested it you put it in the wrong place? =P Thought that might have been it.
haha yep
alright if you dont mind ive got one more question
its a quick one im sure ``` print('' + str(usd) + ' US Dollars converts to: ' + str(round(peso,2)) + ' Argentine Pesos.\n') ``` is there a better way to round to the 100th place (2 decimal place : 0.00) because this method doesnt work quite every time ive noticed
hm maybe it does now, i noticed earlier it wasnt round it to two decimal places when the answer was something like 6.00 it would just put 6.0
String format. Number format... hmm... that is a Java concept. The round might have an extra option.
hm alright
i may just turn it in like this haha, i think ive put more than what was expected to be required into this assignment lol
Looks like they have string format too. Thought so.
yeah i see it too
thanks that should help
Ah, a cleaner example then the entire format docs: http://stackoverflow.com/questions/2389846/python-decimals-format
Oooh. And really good examples: http://mkaz.com/2012/10/10/python-string-format/
oh wow that last one is fantastic! thank you! bookmarking that one
youve got no idea how much i appreciate your help over the past few days :D
Well, that is the hope of the site. Give you someone to talk to that knows a bit more than you do so you can get a few nudges in the right direction.
yep :D i hope ill be able to help some more people the way you do for me soon. really appreciate it, now i havent slept in about 28hrs so im going sleep haha. night. have a wonderful day/night! thanks again!
Join our real-time social learning platform and learn together with your friends!