Python help please! Need help with one last problem with my assignment, code and output posted below even if im not online please help with this! i have been working on this all week and this is the last part i cant figure out.
``` 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): ')) 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 += 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('-----------------------------------------------------------') eval(input('Enter amount to convert (=<0 to exit): ')) num = eval(input('Enter selection: ')) ```
here is my code, i need after you select a number 1-8, i need it to only show that one choice then restart
at the moment what it does is shows all choices after the numberyou choose
my current output after selecting number 3 ``` 1. Argentine Peso 2. Brazilian Real 3. British Pound 4. European Euro 5. Indian Rupee 6. Japanese Yen 7. Russian Ruble 8. Other Enter amount to convert (=< 0 to exit): 55 Enter Selection: 3 55 US Dollars converts to: 43.45 European Euro. 55 US Dollars converts to: 3387.45 Indian Rupee. 55 US Dollars converts to: 6021.95 Japanese Yen. 55 US Dollars converts to: 2169.75 Russian Ruble. Enter current to convert to: yen Enter the conversion factor for yen: .16 55 US Dollars converts to: 8.8 yen. ----------------------------------------------------------- Enter amount to convert (=<0 to exit): ```
@.Sam. are you any good with python?
Still need help with this if anyone can help
I think that after while num > 0: you should remove num += 1 because this ads a part to the input I'd use the following loops: num =str(raw input('...")) while num !=0: etc then you use only 0 to exit the loop Since youǘe got an 'else' statement a negative number would also execute that part otherwhise check under 'else' that num is not negative
ooooh! alright i see what your saying! yeah ill give that a shot
i tried removing the num += 1 before but it sticks me in an infinite loop
add another raw input within the while at the end after the else Iĺl give it a try myself, but it will take a bit longer before Iĺl give another response
erm im sorry but what do you mean by 'raw input'? this is only my first cmps class so im not quite fully knowledgable of all the terminology
ill be back in about an hour, i still need help if theres anything else you would like to post please do so! thanks for help so far!!
GOING TO CLASS
raw_input is an (screen) input statement in python 2.7 (I don't know python 3 (yet) and only started MIT6.00SC a few weeks ago, but have taken a Pascal class ages ago What version do you use?
ahh see i have to use python 3, never learned anything about python 2
if I use the eval I get an error Traceback (most recent call last): File "/home/abt000/conversion_eval.py", line 15, in <module> usd = eval(input('Enter amount to convert (-1 to exit): ')) TypeError: eval() arg 1 must be a string or code object
awhh i see.
i emailed my professor from my phone during class, im hoping she will send me some sort of hint to why mine isnt working.
its weird, my book doesnt even say anything about this problem..
its gotta be something to do witht he num = num+1 part, that sixes the infinite loop but it makes it adds 1 to the selection and runs all after that
@saifoo.khan any chance you know python khan?
No, I don't, but Iĺl google it up. sounds good if thereare Kahn academy videos I looked into the difference between v2 and v2 and I have created a version that would work in both versions. There are also comments, so that you can change it to the eval() version. Are you required to use the eval() ? Since it is not recommended very often: it is a security risk: code can be entered and it can be executed straight away, something that is beyond the control of the programmer I've put the print statements with the choices in a function, because that way it is easy to repeat it later on, but if you haven't done functions yet, you may want to put it back the way it was and remove the call to the function near the end of the program
yeah idk if we are necessarily required to use eval() but thats what our professor suggested and id ont think we've learned anything to replace it yet so im just trying not to really get ahead of myself, i wanna learn what we're doing now and then move forward, ya know what i mean?
wow yours works flawlessly, let me look through it, maybe i can spot whats wrong with mine
yeah we havent learned this ``` def print_choices(): ``` part yet, idk what that does. float we havent learned yet, our class is pretty slow moving, its a class thats meanr to teach as if youve never seen code before. so we have to go over every little thing
the float(x) changes the number x into a float = number with a decimal point if it is an integer (a 'whole' number, a number without a decimal point) a floating point number is for example 3.4 an integer number is for example 3 so the currency rates are floats, the usd are floats (even 1.00 or 67.00 are floating point nrs_ but the num is an integer if you use a floating point number in an if or while statement, you might not get what you would expect, 0.03 might be interpreted as 0
I found a Khan video on exactly the input differences between v2 and 3 http://www.watchknowlearn.org/Video.aspx?VideoID=50676&CategoryID=15530 v2 raw_input() corresponds to v3 input() v2 input corresponds to v3 eval(input()) in MIT6.00SC we were told better not to use input(), but just raw_input() so that conversion to v3 will be easier The other difference is the print statement, but de v3 print statement works in v2.7 too, but not in older versions, I'm told
oooh ok! that makes sense, im kinda remembering floats now that you explained it to me, i had taken a c++ class inh ighschool just dont remember a lot of the stuff from it. thanks
you can easily remove the float() and int() parts from the statments if you're not supposed to use them yet I hope you can finish your assignment now both usd and num input are needed in every cycle so they have to be in the while loop Then only an if is required to check whether to stop or to carry out the currency rate conversion
num is not a counter, but an input is used to decide whether to go on and how, so the num+1 did not make sense
oooh ok i see now, that makes more sense. at first i wasnt quite understanding what you meant by the num+1 wasnt good but now its making sense
yeah i think with all this information you gave me, ill definitely be able to finish my project now.
thank you so so much!
you're welcome, and thanks for giving me a medal and becoming a fan. I hope I'll live up to it
Join our real-time social learning platform and learn together with your friends!