×

1001 pennies

Using Python programming language in mathematics

Purpose of the project:

I started this project to use my Python programming skills to solve a math problem that involved loops, lists, and logic. I wanted to learn how to model processes using code and explore the patterns of replacing items in a list in a practical way. Specifically, I wanted to know how much money would be left on the table after every second, third, and fourth coin was replaced with other types of coins.

Objective:

I implemented a program that solves a math problem with this condition: "There are 1001 pennies lined up on a table. Then I go and replace every second penny with a nickel. After that, I replace every third penny with a dime. Finally, I replace every fourth penny with a quarter. After all this is done, how much money is on the table?" The program simulates the process of replacing 1001 pennies and answers the question: "How much money is on the table?" The ability to work with any number of initial pennies was also added. Finally, the program calculates and displays how much money is left on the table after all the replacements.

Approach:

To solve the problem, I used lists to represent the coins on the table and loops to successively replace a penny with a nickel, dime, or quarter according to certain rules. The program goes through each step of the replacement, changing the appropriate coins, and at the end, sums up the final cost. Additionally, I made the program universal so that it could work for any number of starting pennies, not just 1001, as was originally stated in the problem statement. The program asks the user, “How many pennies are there in total?” and processes this input from user according to the problem conditions, and outputs the final cost.

Project duration:

The project took me about 8 days, including time for coding, testing and debugging.

My role:

I designed and implemented the entire project myself, from concept to completion. My contribution was to design the algorithm for simulating coin replacement, write the code, and optimize it to work with any number of initial pennies. Working on the project helped me better understand loops and lists in Python.

Other Works