Using Functions to Avoid Code Repetition

Functions are a programming concept that allows us to organize our code into sections. This organization makes code easier to read, but also allows the programmer to reuse code throughout a program. As an example, suppose you are making a program that completes the following task.

1. The user is prompted to input numbers until they input “quit”. Each input is run through the formula (input * 2 + 2), and appended to a list

2. Once the user types quit, they are prompted for a final input as a value to search for. This value is also run…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store