Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error?
#10
(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 by int() 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 like a,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
Reply


Messages In This Thread
Error? - by juliabrushett - Jul-02-2018, 03:07 AM
RE: Error? - by Zombie_Programming - Jul-02-2018, 03:51 AM
RE: Error? - by gruntfutuk - Jul-02-2018, 11:43 AM
RE: Error? - by Zombie_Programming - Jul-03-2018, 02:49 AM
RE: Error? - by buran - Jul-03-2018, 04:14 AM
RE: Error? - by Zombie_Programming - Jul-03-2018, 05:43 AM
RE: Error? - by buran - Jul-03-2018, 06:01 AM
RE: Error? - by Zombie_Programming - Jul-03-2018, 06:18 AM
RE: Error? - by gruntfutuk - Jul-03-2018, 11:22 AM
RE: Error? - by buran - Jul-03-2018, 06:23 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020