Note 1: Please code this exercise in your local IDE.

Note 2This is a very challenging exercise. The main purpose here is to get you through the discomfort of problem-solving to prepare you for real-life coding.


A client wants to buy a coin-flip probability program from you.

The programs should work like this:

1. The user runs the program. The program asks the user to enter "head" or "tail".  The user flips a coin on their desk, table, floor, etc., and then enters "head" or "tail". The user does the same over and over again.


In each cycle, the program should return the current percentage of heads in the program, similar to what you see in the screenshot above. Also, you should write each user entry (i.e., head or tail) in a text file using a with-context manager, one entry per line.

Solution