Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ optimize and capitalize on what I and whoever else have and will learn.

## NUMBERS
- [X] **Find PI to the Nth Digit** - Enter a number and have the program generate PI up to that many decimal places. Keep a limit to how far the program will go.
- [ ] **Find e to the Nth Digit** - Just like the previous problem, but with e instead of PI. Enter a number and have the program generate e up to that many decimal places. Keep a limit to how far the program will go.
- [ ] **Fibonacci Sequence** - Enter a number and have the program generate the Fibonacci sequence to that number or to the Nth number.
- [ ] **Prime Factorization** - Have the user enter a number and find all Prime Factors (if there are any) and display them.
- [ ] **Next Prime Number** - Have the program find prime numbers until the user chooses to stop asking for the next one.
- [ ] **Find Cost of the Tile to Cover W x H Floor** - Calculate the total cost of tile it would take to cover a floor plan of width and height, using a cost entered by the user.
- [ ] **Mortgage Calculator** - Calculate the monthly payments of a fixed term mortgage over given Nth terms at a given interest rate. Also figure out how long it will take the user to pay back the loan. For added complexity, add an option for users to select the compounding interval (Monthly, Weekly, Daily, Continually).
- [ ] **Change Return Program** - The user enters a cost and then the amount of money given. The program will figure out the change and the number of quarters, dimes, nickels, pennies needed for the change.
- [ ] **Binary to Decimal and Back Converter** - Develop a converter to convert a decimal number to binary or a binary number to its decimal equivalent.
- [ ] **Simple Calculator** - A simple calculator to do basic operators.
- [ ] **Unit Converter (temp, currency, volume, mass)** - Converts various units between one another. The user enters the type of unit being entered, the type of unit they want to convert to and then the value. The program will then make the conversion.
- [X] **Find e to the Nth Digit** - Just like the previous problem, but with e instead of PI. Enter a number and have the program generate e up to that many decimal places. Keep a limit to how far the program will go.
- [X] **Fibonacci Sequence** - Enter a number and have the program generate the Fibonacci sequence to that number or to the Nth number.
- [X] **Prime Factorization** - Have the user enter a number and find all Prime Factors (if there are any) and display them.
- [X] **Next Prime Number** - Have the program find prime numbers until the user chooses to stop asking for the next one.
- [X] **Find Cost of the Tile to Cover W x H Floor** - Calculate the total cost of tile it would take to cover a floor plan of width and height, using a cost entered by the user.
- [X] **Mortgage Calculator** - Calculate the monthly payments of a fixed term mortgage over given Nth terms at a given interest rate. Also figure out how long it will take the user to pay back the loan. For added complexity, add an option for users to select the compounding interval (Monthly, Weekly, Daily, Continually).
- [X] **Change Return Program** - The user enters a cost and then the amount of money given. The program will figure out the change and the number of quarters, dimes, nickels, pennies needed for the change.
- [X] **Binary to Decimal and Back Converter** - Develop a converter to convert a decimal number to binary or a binary number to its decimal equivalent.
- [X] **Simple Calculator** - A simple calculator to do basic operators.
- [X] **Unit Converter (temp, currency, volume, mass)** - Converts various units between one another. The user enters the type of unit being entered, the type of unit they want to convert to and then the value. The program will then make the conversion.
- [ ] **Alarm Clock** - A simple clock where it plays a sound after X number of minutes/seconds or at a particular time.
- [ ] **Distance Between Two Cities** - Calculates the distance between two cities and allows the user to specify a unit of distance. This program may require finding coordinates for the cities like latitude and longitude.
- [ ] **Tax Calculator** - Asks the user to enter a cost and either a country or state tax. It then returns the tax plus the total cost with tax.
- [X] **Distance Between Two Cities** - Calculates the distance between two cities and allows the user to specify a unit of distance. This program may require finding coordinates for the cities like latitude and longitude.
- [X] **Tax Calculator** - Asks the user to enter a cost and either a country or state tax. It then returns the tax plus the total cost with tax.
- [ ] **Credit Card Validator** - Takes in a credit card number from a common credit card vendor (Visa, MasterCard, American Express, Discoverer) and validates it to make sure that it is a valid number (look into how credit cards use a checksum).
- [ ] **Factorial Finder** - The Factorial of a positive integer, n, is defined as the product of the sequence n, n-1, n-2, ...1 and the factorial of zero, 0, is defined as being 1. Solve this using both loops and recursion.
- [ ] **Fast Exponentiation** - Ask the user to enter 2 integers a and b and output a^b (i.e. pow(a,b)) in O(lg n) time complexity.
Expand Down
Binary file added alarm-tone.wav
Binary file not shown.
35 changes: 35 additions & 0 deletions alarm_clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Program a simple alarm clock that plays a sound after a few minutes/seconds.
#
# Started: 6 March 2023
# Completed: xx March 2023

# import time
# # from pydub import AudioSegment
# # from pydub.playback import play
# import sounddevice as sd
# import soundfile as sf

# # song = AudioSegment.from_wav("alarm-tone.wav")

# filename = 'alarm-tone.wav'
# data, fs = sf.read(filename, dtype='float32')

# user_seconds = float(input("How many seconds do you want to wait before the alarm goes off? "))
# user_minutes = float(input("How many minutes do you want to wait before the alarm goes off? "))
# user_hours = float(input("How many hours do you want to wait before the alarm goes off? "))

# print("")
# timer_seconds = float(user_seconds + (user_minutes * 60) + (user_hours * 60 * 60))

# print("Waiting...")
# time.sleep(timer_seconds)
# # play(song)
# # print("Alarm went off...")
# sd.play(data, fs)
# status = sd.wait()

from pydub import AudioSegment
from pydub.playback import play

sound = AudioSegment.from_wav('alarm-tone.wav')
play(sound)
37 changes: 37 additions & 0 deletions binary_decimal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Program converts a decimal number to binary or a binary to it's decimal
# equivalent.
#
# Started: 19 January 2023
# Completed: 24 January 2023

import math

def deciToBin(decimal_num):
temp = int(decimal_num)
remainder = -1
binary = ''

while temp / 2 != 0:
remainder = temp % 2
binary = str(remainder) + binary
temp = int(temp / 2)

return binary


def binToDeci(binary_num):
temp = str(binary_num)
power = 0
result = 0

while len(temp) > 0:
if temp[-1:] == "1":
result = result + math.pow(2,power)

power += 1
temp = temp.replace(temp, temp[:-1])

return result

print("15 converted to binary format is %s" % deciToBin(15))
print("1101 converted to decimal format is %d" % binToDeci(1101))
55 changes: 55 additions & 0 deletions change_return.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# User enter a cost and then the amount given. The program will figure out the
# change and the number of quarters, dimes, nickels, pennies needed for the change.
#
# Started: 18 January 2023
# Completed: 18 January 2023

import math

def changeCalulate(price, payment):
# Calculate the amount of change we need to make. Print it out to the user
temp_difference = int( math.ceil((payment - price) * 100))
print("Change: $%.2f" % (temp_difference * 0.01))
# Calculate quarter count
quarterCount = (temp_difference - (temp_difference % 25)) / 25
temp_difference = temp_difference % 25
# Calculate dime count
dimeCount = (temp_difference - (temp_difference % 10)) / 10
temp_difference = temp_difference % 10
# Calculate nickel count
nickelCount = (temp_difference - (temp_difference % 5)) / 5
# Calculate penny count
pennyCount = temp_difference % 5
# Print out the change and coin count
print("Your change is in %d quarters, %d dimes, %d nickels, and %d pennies." % (quarterCount, dimeCount, nickelCount, pennyCount))


def checkPayment(price, payment):
# Check to make see if the payment is less than the price
# If so, ask for more money
if (payment < price):
print("That is not enough to cover the purchase.")
user_inp = input("Please enter more money: ")
addedMoney = float(user_inp)
payment += addedMoney
checkPayment(price, payment)
# Check to see if the payment is equal to the price.
# If so, no change necessary. Otherwise, payment is greater than the price
elif payment == price:
print("Thank you! No change necessary.")
else:
changeCalulate(price, payment)

def main():
# Ask the user for the price of the purchase. Cast into a float
user_inp = input("Purchase Price: ")
price = float(user_inp)

# Ask the user for the amount they gave. Cast into a float
user_inp = input("How much are you giving? ")
user_money = float(user_inp)

checkPayment(price, user_money)

if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions cost_of_tile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Have the program calculate the total cost of tile it would take to cover
# a floor plan of x width and y height, using a cost entered by the user.
#
# Started: 15 January 2023
# Completed: 15 January 2023

user_inp = input("How much do the tiles cost? ")
tile_price = float(user_inp)

user_inp = input("What is the width of the area you're tiling? ")
area_width = float(user_inp)

user_inp = input("What is the height of the area you're tiling? ")
area_height = float(user_inp)

total_price = float(tile_price * (area_height * area_width))
print("Total price for the area: $%.2f" % total_price)
65 changes: 65 additions & 0 deletions dist_btwn_cities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Write a program that calculates the distance between two cities and
# allows the user to specify a unit of distance. May require finding
# coordinates for the citie like latitude and longitude.
#
# Started: 07 March 2023
# Completed: 25 April 2023

# Importing the geodesic module from the library
from geopy import distance
from geopy.distance import geodesic

# Function for checking if the user entered city is in our dictionary
def check_city(city, flag_num):
if city in cities_dict:
flag_found_key[flag_num] = True
else:
print("Try a different city...")

# Function to check if the user entered unit is in our list
def check_unit(unit):
return True if unit in units_of_dist else False

# Function to calculate the distance using the geodesic function in geopy
# according to the unit the user requested
def calculate_dist():
if user_unit.lower().__eq__("km") or user_unit.lower().__eq__("kilometers"):
print("%.3f kilometers" % geodesic(cities_dict[user_cities[0].upper()], cities_dict[user_cities[1].upper()]).km)
elif user_unit.lower().__eq__("m") or user_unit.lower().__eq__("meters"):
print("%.3f meters" % geodesic(cities_dict[user_cities[0].upper()], cities_dict[user_cities[1].upper()]).m)
else:
print("%.3f miles" % geodesic(cities_dict[user_cities[0].upper()], cities_dict[user_cities[1].upper()]).mi)

# Created dictionary of top 10 major US cities and list of units of distance
cities_dict = {
"CHICAGO": [25.7617, -80.1918],
"DALLAS": [32.779167, -96.808891],
"HOUSTON": [29.749907, -95.358421],
"LOS ANGELES": [34.052235, -118.243683],
"NEW YORK": [40.730610, -73.935242],
"PHILADELPHIA": [39.952583, -75.165222],
"PHOENIX": [33.448376, -112.074036],
"SAN ANTONIO": [29.424349, -98.491142],
"SAN DIEGO": [32.715736, -117.161087],
"SAN JOSE": [37.335480, -121.893028]
}
units_of_dist = ["km", "kilometers", "m", "meters", "mi", "miles"]

# Created flag array for checking cities and array of user cities
flag_found_key = [False, False]
flag_valid_unit = False
user_cities = ["", ""]

# Loop through both flags and cities arrays to check and change flags accordingly
for x in range(0,2):
while not flag_found_key[x]:
user_cities[x] = input("Enter a US city: ")
check_city(user_cities[x].upper(), x)

# Loop to accept the user's unit of distance and ask for
# another if the entered unit is invalid
while not flag_valid_unit:
user_unit = input("Enter a valid unit of measurement: ")
flag_valid_unit = check_unit(user_unit.lower())

calculate_dist()
29 changes: 29 additions & 0 deletions fibonacci_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Enter a number and have the program generate the Fibonacci sequence to that
# number OR to the Nth number, whichever occurs first.
#
# Started: 14 January 2023
# Completed: 14 January 2023

def fibonacci(user_num):
tracker = 3
num1 = 0
num2 = 1
fib_num = num1 + num2
print(num1)
print(num2)
print(fib_num)
while (user_num != fib_num) and (tracker != user_num):
num1 = num2
num2 = fib_num
fib_num = num1 + num2
tracker += 1
print(fib_num)
if (user_num == fib_num):
print("Went to the number you input.")
else:
print("Went to the Nth number of the sequence.")

user_inp = input("Enter a number: ")
user_num = int(user_inp)

fibonacci(user_num)
30 changes: 30 additions & 0 deletions mortgage_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Calculate the montly payments of a fixed term mortgage over given Nth terms
# at a given interest rate. Also, figure out how long it will take the user to
# pay back the loan.
# Added Complexity: add an option for users to select the compounding interval
# (monthly, weekly, daily, continually)
#
# Started: 15 January 2023
# Completed: XX January 2023

import math
# Ask the user for the value of the mortgage
user_inp = input("What is the value of the mortgage? ")
mortgage_val = float(user_inp)

# Ask the user for the interest rate
user_inp = input("What is the interest rate? ")
interest_rate = float(user_inp)

# Ask the user the number of months of the loan
user_inp = input("How many months is the mortgage good for? ")
term_length = int(user_inp)

# Calculate the monthly payments
monthly_interest_rate = float((interest_rate / 100) / 12)
print("Monthly Interest Rate: %f" % monthly_interest_rate)
monthly_interest_rate1 = float(1 + monthly_interest_rate)
monthly_payments = float((mortgage_val * (monthly_interest_rate * math.pow(1 + monthly_interest_rate, term_length)) / ( (math.pow(1 + monthly_interest_rate, term_length)) - 1 )))

# Print the monthly payments
print("Monthly Payments: $%.2f" % monthly_payments)
45 changes: 45 additions & 0 deletions next_prime_num.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Have the program find prime numbers until the user chooses to stop asking for the next one.
#
# Started: 14 January 2023
# Completed: 14 January 2023

import math

# Function to check whether the user wants the next prime number
def check_user(num_check):
if(num_check == 0):
user_inp = input("Would you like to see a prime number?(Y/N) ")
else:
user_inp = input("Would like to see the next prime number?(Y/N) ")

if user_inp.capitalize() == 'Y':
nextPrime(num_check)
elif user_inp.capitalize() == 'N':
print("Goodbye!")

# Function to print the next prime number
def nextPrime(num):
if (isPrime(num)):
print(num)
check_user(num+1)
else:
nextPrime(num+1)
pass

# Function to check whether the current number is a prime number
def isPrime(num):
if num <= 1:
return False
if num <= 3:
return True

if (num % 2 == 0 or num % 3 == 0):
return False

for i in range(5, int(math.sqrt(num) + 1), 6):
if (num % i == 0 or num % (i + 2) == 0):
return False

return True

check_user(0)
31 changes: 31 additions & 0 deletions prime_factorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# User enters a number. Have the program find all Prime Factors (if there are any) and
# display them.
#
# Started: 14 January 2023
# Completed: 14 January 2023

# Function to find the prime factors of user input number
def prime_factorization(num):
# A list to keep track of prime factors
prime_factors = []
# int variable to hold factorized number and to check when we reach 1 or a prime number
factorized_num = num

# While loop to check when we hit 1
while factorized_num != 1:
# For loop to go through prime numbers since user number can be any size.
# Will break out of for loop when we find the smallest prime number that can
# divided into user's num
for x in range(2,num):
if factorized_num % x == 0:
prime_factors.append(x)
factorized_num = factorized_num / x
break
# Print prime factors list for user's num
print("Prime Factors of", num, ":",prime_factors)

# Ask user for number and cast it into an integer
user_inp = input("Enter a number: ")
user_num = int(user_inp)
# Call prime factorization method with user's number
prime_factorization(user_num)
Loading