Jul-03-2018, 11:22 AM
(This post was last modified: Jul-03-2018, 11:22 AM by gruntfutuk.)
(Jul-03-2018, 06:18 AM)Zombie_Programming Wrote:(Jul-03-2018, 06:01 AM)buran Wrote: We were told to use eval() since int() and float() do not iterate.I'm not sure what you mean byint() and float() do not iterate
I miss spoke by saying iterate, what I meant to say that having a user input numbers, like in the program the person was trying to do here, doing it with by saying something likea,b = int(input('Enter A and B: "))
will produce this error.
Error:Traceback (most recent call last): File "C:\Users\bagpi\Desktop\test.py", line 1, in <module> a,b = int(input("Enter A and B: ")) ValueError: invalid literal for int() with base 10: '1,2'
The OP was trying to unpack two integer values from one string: not going to work.
I provided one alternative approach that is pretty succinct, although lacks error checking (so programme will stop if the user does not enter two integers with a space between them) that I thought sufficient for a beginner. I personally would normally write a function to manage data input and validation (probably using a try/exception block).
For a beginner, it might have been better to just have two input statements, frankly rather than collect two inputs at the same time.
I am trying to help you, really, even if it doesn't always seem that way