Skip to content
Merged
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
3 changes: 1 addition & 2 deletions code/kaceyb/python/lab08/lab_08.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# PART 1 #


from logging import exception
import requests


Expand Down Expand Up @@ -41,6 +39,7 @@

joke = response.json()
jokes = joke["results"]

try:

for joke in jokes:
Expand Down
69 changes: 69 additions & 0 deletions code/kaceyb/python/lab09/lab_09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# VERSION 1 #


import json
import requests

# response = requests.get("https://favqs.com/api/qotd")

#
# print(response)
# print(type(response))
# print(response.text)
# print(response.status_code)

# quote = response.text
# json_response = response.json()

# quote_author = json_response['quote']['author']

# quote_body = json_response['quote']['body']

# print(f'The author is {quote_author}\nTheir quote: {quote_body}')


# VERSION 2 #



page_number = 1 # Starts page_number at page 1

search_term = input("Enter a keyword to search for quotes: ") # Gives the user an input to search for term


def get_response(search_term): # Make a function to make code reusable and keep program clean
""" Pulls JSON from API and converts it into a dictionary

Args:
search_term (string): Term that the API uses to search with

Returns:
boolean: True if last page, False if not
dictionary: API response(big jumbled mess of dictionary key/value pairs)
"""
response = requests.get(
f"https://favqs.com/api/quotes?page={page_number}&filter={search_term}", # F string that builds the API URL
headers={"Authorization": 'Token token="855df50978dc9afd6bf86579913c9f8b"'}, # API Token which gives access [200]=Success [401]=Unathorized
)

json_response = response.json() # creates dictionary from JSON

is_last_page = json_response["last_page"] # "last_page is a field inside JSON_response which returns True or False THEN assigns it to is_last_page"

return is_last_page, json_response


is_last_page = False # Assigning False so the loop will run at least once
quotes_list = [] # Assigning an Empty list to the quotes_list(initiating dictionary)
while is_last_page == False: # Beginning while loop
is_last_page, json_response = get_response(search_term) # Calling function and assigning responses
for i in range(len(json_response["quotes"])): # For loop to loop through all the quotes

author_json = json_response["quotes"][i]["author"] # Get author from quotes for the current quote, i
quote_json = json_response["quotes"][i]["body"] # Get quote body from quotes for the current quote, i

print(f'"{quote_json}"\nBy {author_json}\n') # Print formatted string to display the quote and author
user_is_done = input("enter 'next page' or 'done': ").lower().strip() # Ask the user if they want to continue
page_number += 1 # Incrementing page_number by 1 each loop
if user_is_done == "done": # Taking user inputs "done" and breaking the loop ending the program
break
74 changes: 74 additions & 0 deletions code/kaceyb/python/lab10/lab_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class ATM:
def __init__(self):
self.balance = 0
self.transactions = []

def check_balance(self):
return round(self.balance, 2)

def deposit(self, amount):
self.balance = self.balance + amount
self.transactions.append(f'user deposited ${amount}')
return self.balance

def withdraw(self, amount):
self.balance = self.balance - amount
self.transactions.append(f'user withdrew ${amount}')
return self.balance

def check_withdrawal(self, amount):
if amount > self.balance:
return False
return True

def calc_interest(self):
calc_interest = (self.balance * .1) / 100
return round(calc_interest, 2)

def print_transactions(self):
for transaction in self.transactions:
print(transaction)







atm = ATM() # create an instance of our class
print('Welcome to the ATM')
while True:
command = input('Enter a command: ')
if command == 'balance':
balance = atm.check_balance() # call the check_balance() method
print(f'Your balance is ${balance}')
elif command == 'deposit':
amount = float(input('How much would you like to deposit? '))
atm.deposit(amount) # call the deposit(amount) method
print(f'Deposited ${amount}')
elif command == 'withdraw':
amount = float(input('How much would you like '))
if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method
atm.withdraw(amount) # call the withdraw(amount) method
print(f'Withdrew ${amount}')
else:
print('Insufficient funds')
elif command == 'interest':
amount = atm.calc_interest() # call the calc_interest() method
atm.deposit(amount)
print(f'Accumulated ${amount} in interest')
elif command == 'transactions':
atm.print_transactions()
elif command == 'help':
print('Available commands:')
print('balance - get the current balance')
print('deposit - deposit money')
print('withdraw - withdraw money')
print('interest - accumulate interest')
print('transactions - list of all transactions')
print('exit - exit the program')

elif command == 'exit':
break
else:
print('Command not recognized')
38 changes: 38 additions & 0 deletions code/kaceyb/python/notes/lesson06/class_lesson_12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# with open('location.csv', 'w') as file:
# file.write("Hello World")

# # with open(file, 'r') as f:
# # contents = f.readlines()
# # print(contents)

# with open(file, 'r') as f:
# for line in f:
# list.append(line)

# phonebook = {'Dave': '42342', 'Alice': '234234'}
# with open(file, 'w') as location:
# for name, number in location.items():
# line = f'{name}{number}\n'
# location.write(line)


# CSV = comma separated values

# with open('contacts.csv', 'w') as file:
# lines = file.read().split('\n')
# print(lines)

contacts = [
{"name": "matthew", "favorite fruit": "blackberries", "favorite color": "orange"},
{"name": "sam", "favorite fruit": "pineapple", "favorite color": "purple"},
{"name": "teeto", "favorite fruit": "lychee", "favorite color": "brown"},
]

f = open("contacts.csv")

with open("contacts.csv", "r") as contacts:
contacts_data = contacts.read().split("\n")

dict = []
for line in contacts_data:
dict.append(contacts_data)
43 changes: 35 additions & 8 deletions code/kaceyb/python/notes/lesson06/lesson_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,44 @@
# def __init__(self, username, email):
# self.username = username
# self.email = email

# bruce = User('criticbruce', 'cd@email.com')

# print(bruce.username)

# SECOND PIECE #

import math



def distance(p1, p2):
dx = p1["x"] - p2["x"]
dy = p1["y"] - p2["y"]
return math.sqrt(dx * dx + dy * dy)


p1 = {"x": 5, "y": 2}
p2 = {"x": 8, "y": 4}
print(distance(p1, p2))


class Point:
def __init__(self, x, y):
self.x = x
self.y = y

def distance(self, p):
dx = self.x - p.x
dy = self.y - p.y
return math.sqrt(dx * dx + dy * dy)


p1 = Point(5, 2) # call the initializer, instantiate the class

p1 = (5, 2)
p2 = Point(8, 4)

def distance(p1, p2):
dx = p1['x'] - p2['x']
dy = p1['y'] - p2['y']
Expand Down Expand Up @@ -41,16 +71,13 @@ def distance(self, p):
print(type(p1))
# print(p1.distance(p2))


name = [1, 2, 3]

name = [1,2,3]

print(type(name))
print(name.sort())

number = input("What's your favorite number?: ")
print(type(number))







Empty file.
1 change: 1 addition & 0 deletions code/kaceyb/python/notes/lesson06/location.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
Empty file.
30 changes: 27 additions & 3 deletions code/kaceyb/python/notes/lesson06/notes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# with open('example.txt', 'a') as file:
# text = file.write('\nMORE TEXT')

# print(text)
# print(text)

# file = open('example2.txt', 'w')
Expand All @@ -9,6 +11,10 @@

# with open('colors.txt') as file:
# colors = file.read()

# colors = file.read().split()
# print(colors)


# colors = file.read().split()
# print(colors)
Expand All @@ -17,6 +23,9 @@
# text = file.write()
# print(text)

# import datetime

# read file
# import datetime

#read file
Expand All @@ -34,6 +43,11 @@

# with open('phonebook.txt') as file:
# phone_book = file.read()

# phone_book = phone_book.split('\n')
# name = input('Lookup name: ')



# phone_book = phone_book.split('\n')
# name = input('Lookup name: ')
Expand All @@ -43,19 +57,27 @@
# if name.lower() in entry.lower():
# print(entry)
# found_entry = True




# if not found_entry:
# print('Contact not found')
# name = input('Enter new contact name: ')
# phone_number = input(f'Enter the number for : {name}')

# phone_book.append(name + " " + phone_number)

# phone_book.sort()
# with open('phonebook2.txt', 'w') as file2:
# file2.write('\n'.join(phone_book))


# phone_book.append(name + " " + phone_number)

# phone_book.sort()
# with open('phonebook2.txt', 'w') as file2:
# file2.write('\n'.join(phone_book))


# print(type(phone_book))
# print(phone_book)
# def Convert(lst):
Expand All @@ -66,4 +88,6 @@
# color = file.read()
# color = color.split('\n')
# color = Convert(color)
# print(color)
# print(color)

# print(color)
13 changes: 12 additions & 1 deletion code/kaceyb/python/notes/lesson06/notes2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

# # for category in categories:
# # print(category)

# for i in range(len(categories)):
# print(i, categories[i])


# for i in range(len(categories)):
# print(i, categories[i])
Expand All @@ -42,16 +46,23 @@


import requests

url = "https://ghibliapi.herokuapp.com/films"

url = 'https://ghibliapi.herokuapp.com/films'
response = requests.get(url)
# print(response.text)
data = response.json()
# print(data[0]['title'])
for film in data:
print(film["title"])
print(film["release_date"])
print(film["description"])

print("-" * 10)
print(film['title'])
print(film['release_date'])
print(film['description'])


print('-'*10)