E X E R C I S E # 2 6 : H A N D S H A K E S There is only one handshake that can happen between two people. Between three people, there
are three possible handshaking pairs. Between four people, there are six handshakes; five people, ten
handshakes, and so on. This exercise explores the full range of possible handshaking combinations
with nested for loops.
Exercise Description Write a function named printHandshakes() with a list parameter named people which will
be a list of strings of people’s names. The function prints out 'X shakes hands with Y', where
X and Y are every possible pair of handshakes between the people in the list. No duplicates are
permitted: if ―Alice shakes hands with Bob‖ appears in the output, then ―Bob shakes hands with
Alice‖ should not appear.
For example, printHandshakes(['Alice', 'Bob', 'Carol', 'David']) should
print:
Alice shakes hands with Bob
Alice shakes hands with Carol
Alice shakes hands with David
Bob shakes hands with Carol
Bob shakes hands with David
Carol shakes hands with David
The printHandshakes() function must also return an integer of the number of handshakes.
These Python assert statements stop the program if their condition is False. Copy them to
the bottom of your solution program. Your solution is correct if the output displays all possible
handshakes and the following assert statements’ conditions are all True:
assert printHandshakes(['Alice', 'Bob']) == 1
assert printHandshakes(['Alice', 'Bob', 'Carol']) == 3
assert printHandshakes(['Alice', 'Bob', 'Carol', 'David']) == 6
Try to write a solution based on the information in this description. If you still have trouble
solving this exercise, read the Solution Design and Special Cases and Gotchas sections for
additional hints.
Prerequisite concepts: for loops, range() with two arguments, len(), augmented assignment
operators