division
Ben Finney
bignose-hates-spam at and-zip-does-too.com.au
Sun Jun 22 23:18:21 EDT 2003
On Mon, 23 Jun 2003 03:41:28 +0100, kpop wrote:
> thanks for the help, I think i will change all the numbers to floating
> points then do the eval
> and if the result is not a float that end with..0
Rather than using string processing (slow, difficult to understand,
prone to error), use modulus to find the remainder (fast, obvious,
built-in):
remainder = ( result % 1.0 )
if( remainder > 0.0 ):
raise SomeExceptionYouCreatedForThePurpose
> i will inform the user they typed something wrong
I think your program design needs re-thinking. If I typed "4 / 3" into
an arithmetic evaluator, and was told that was an error, I'd certainly
consider it a design bug in the program.
Can you explain more fully what it is you want to do? Why do you
consider a fractional result to be an error?
--
\ "It's easy to play any musical instrument: all you have to do |
`\ is touch the right key at the right time and the instrument |
_o__) will play itself." -- Johann Sebastian Bach |
http://bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B
More information about the Python-list
mailing list