[Tutor] Complicating a simple expression (Python 3)
Joseph Gulizia
joseph.gulizia at gmail.com
Sun Aug 16 22:28:19 CEST 2015
Complicating a simple expression
Coding Exercise: Complication
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.
Hint, Method 1
What is max(-A, -B)?
Hint, Method 2
What is min(A, B)+max(A, B)?
My last code that worked somewhat
-----------------------------------
Original = max(A, B)
Opposite = max(-A, -B)
Grader =max(-A,- B)+max(A, B)
print (Grader)
------------------------------------
Did not pass tests. Please check details below and try again.
Results for test case 1 out of 5
Before running your code: We defined A equal to 62 and B equal to 36.
Program executed without crashing.
Program output:
26
Expected this correct output:
36
Result of grading: Your output is not correct.
Spreadsheet examples:
A B Max(A, B) Min(A, B) Min(A, B)+Max(A, B) Max(A,
B)+Max(A, B) Min(A, B)+Min(A, B)
10 5 10 5 15 20 10
5 10 10 5 15 20 10
9 12 12 9 21 24 18
12 9 12 9 21 24 18
22 37 37 22 59 74 44
37 22 37 22 59 74 44
45 68 68 45 113 136 90
68 45 68 45 113 136 90
Max(-A,- B) Max(-A,- B)+Max(A, B) Max(-A,- B)-Max(A, B)
-5 5 -15
-5 5 -15
-9 3 -21
-9 3 -21
-22 15 -59
-22 15 -59
More information about the Tutor
mailing list