Komodo Dragon from the Virginia Aquariam.

Bio
Iā€™m a junior majoring in Computer Science and minoring in Data Science. Born and raised in Virginia my whole life.

Likes
  • Action/comedy movies and shows
  • Junk foods
  • Partner Dancing
  • Multiplayer videogames

Sample Script

Change Calculator (.py)

My sample script is from a project did I did in a computer science class a couple years ago. I modified a little bit by importing argparse and adding in a useful help message. This script takes an integer that represents a number of cents as an input and uses an algorithm to determine the best combination of common American coins that would be needed to generate this number, using as few coins as possible. This script is perfect for determining how to make exact change for any positive number of cents.

Format to run the script:

python change_calculator.py integerOfYourChoice
import argparse


def change(amount):
    if amount < 0:
        raise ValueError('It\'s impossible to have a negative number of cents. Please try again.')
    #The amount can't be negative

    change_count = dict() #This dictionary keeps track of the number of each American coin
    quarters = int(amount/25)
    amount-=(quarters * 25)
    dimes = int(amount/10)
    amount-=(dimes * 10)
    nickels = int(amount/5)
    amount-=(nickels * 5)
    pennies = amount

    change_count['Quarters'] = quarters
    change_count['Dimes'] = dimes
    change_count['Nickels'] = nickels
    change_count['Pennies'] = pennies
    return change_count

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Find the combination of the smallest number of common American coins (quarters, dimes, nickels, and pennies) that add up to the given number of cents. The number of cents needs to be represented by an integer and must be positive.')
    parser.add_argument('amount', type=int, help="The total number of cents (integer)")
    args = parser.parse_args()
    print("The number of quarters, dimes, nickels, and pennies needed to generate exact change: ", change(args.amount))