Test Informed Learning with Examples

Logo

Repository with assignments using the Test Informed Learning with Examples (TILE) method to integrate testing into existing programming courses for free.

Menu

Three-way value swapping

Make a program in Python that receive values for three variables

a, b and c, and interchange their values as follows:

This must be done WITHOUT using auxiliary variables, that is, additional helper variables that are not a, b or c, and are used to store some values.

Execute tests through the console and check the output. Does your program work for negative numbers? Does it work for characters? Does it work for reals? Can a, b and c have different types? Should your program work for all these cases?

This exercise was TILEd by adding the last paragraph. We explicitly
ask the students to test for different types of values. Most
students, because of the example execution convert the user input to
int, but that is not necessary for the swapping, anything can be
swappped. Asking them to test with all kinds of values makes them
aware of the assumptions they made when reading the exercises and
hence how testing is good to find errors.