int vs. float
Marko Rauhamaa
marko at pacujo.net
Sat Feb 11 03:24:32 EST 2017
boB Stepp <robertvstepp at gmail.com>:
> According to the OP's professor's challenge, the OP needs to recognize
> an input of "4.0" as a float and "4" as an integer, and to respond
> with an error message in the float case, or "decimal number" case as
> the OP phrased it. Apparently only positive integers are acceptable
> input; all other inputs should generate an appropriate error message
> by input type.
Haven't been following the discussion, but this should be simply:
ast.literal_eval("...")
For example:
>>> ast.literal_eval("( 1.0, 3 )").__class__.__name__
'tuple'
Marko
More information about the Python-list
mailing list