[Tutor] Complications Take Two (Long) Frustrations.

Joel Goldstick joel.goldstick at gmail.com
Fri Aug 21 23:22:09 CEST 2015


On Fri, Aug 21, 2015 at 4:58 PM, Roel Schroeven <roel at roelschroeven.net> wrote:
> 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.
>
>
> Regards,
> Roel
>
> --
> The saddest aspect of life right now is that science gathers knowledge
> faster than society gathers wisdom.
>   -- Isaac Asimov
>
> Roel Schroeven
>

so:
    print -max(-A, -B)
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



-- 
Joel Goldstick
http://joelgoldstick.com


More information about the Tutor mailing list