[Tutor] Complications Take Two (Long) Frustrations.

Roel Schroeven roel at roelschroeven.net
Fri Aug 21 22:58:23 CEST 2015

Joseph Gulizia schreef op 2015-08-20 05:12:
> Assume that the grader defines two variables A and B for you. Write a
> program which prints out the value
> min(A, B)
> However, there is a catch: your program is not allowed to use the min
> function. Instead, use max in a clever way to simulate min.
> --------------------------------------
> Code that gave best results but didn't work for negative numbers...
> --------------------------------------
> Original = abs(max (-A, -B))
> print (Original)
> --------------------------------------
> Did not pass tests.

You change the sign of A and B before passing them to max(). To revert 
that afterwards, you just need to change the sign of the result again.

abs() indeed doesn't work for that: it only changes the sign on negative 
numbers, not on positive numbers.


The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

Roel Schroeven

More information about the Tutor mailing list