Skip to content

Commit 99009fb

Browse files
authored
Merge pull request #124 from PdxCodeGuild/kacey-lab10-atm
Kacey lab10 atm
2 parents 3fc40bd + 5aefc2b commit 99009fb

File tree

10 files changed

+257
-14
lines changed

10 files changed

+257
-14
lines changed

code/kaceyb/python/lab08/lab_08.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# PART 1 #
22

3-
4-
from logging import exception
53
import requests
64

75

@@ -41,6 +39,7 @@
4139

4240
joke = response.json()
4341
jokes = joke["results"]
42+
4443
try:
4544

4645
for joke in jokes:

code/kaceyb/python/lab09/lab_09.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# VERSION 1 #
2+
3+
4+
import json
5+
import requests
6+
7+
# response = requests.get("https://favqs.com/api/qotd")
8+
9+
#
10+
# print(response)
11+
# print(type(response))
12+
# print(response.text)
13+
# print(response.status_code)
14+
15+
# quote = response.text
16+
# json_response = response.json()
17+
18+
# quote_author = json_response['quote']['author']
19+
20+
# quote_body = json_response['quote']['body']
21+
22+
# print(f'The author is {quote_author}\nTheir quote: {quote_body}')
23+
24+
25+
# VERSION 2 #
26+
27+
28+
29+
page_number = 1 # Starts page_number at page 1
30+
31+
search_term = input("Enter a keyword to search for quotes: ") # Gives the user an input to search for term
32+
33+
34+
def get_response(search_term): # Make a function to make code reusable and keep program clean
35+
""" Pulls JSON from API and converts it into a dictionary
36+
37+
Args:
38+
search_term (string): Term that the API uses to search with
39+
40+
Returns:
41+
boolean: True if last page, False if not
42+
dictionary: API response(big jumbled mess of dictionary key/value pairs)
43+
"""
44+
response = requests.get(
45+
f"https://favqs.com/api/quotes?page={page_number}&filter={search_term}", # F string that builds the API URL
46+
headers={"Authorization": 'Token token="855df50978dc9afd6bf86579913c9f8b"'}, # API Token which gives access [200]=Success [401]=Unathorized
47+
)
48+
49+
json_response = response.json() # creates dictionary from JSON
50+
51+
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"
52+
53+
return is_last_page, json_response
54+
55+
56+
is_last_page = False # Assigning False so the loop will run at least once
57+
quotes_list = [] # Assigning an Empty list to the quotes_list(initiating dictionary)
58+
while is_last_page == False: # Beginning while loop
59+
is_last_page, json_response = get_response(search_term) # Calling function and assigning responses
60+
for i in range(len(json_response["quotes"])): # For loop to loop through all the quotes
61+
62+
author_json = json_response["quotes"][i]["author"] # Get author from quotes for the current quote, i
63+
quote_json = json_response["quotes"][i]["body"] # Get quote body from quotes for the current quote, i
64+
65+
print(f'"{quote_json}"\nBy {author_json}\n') # Print formatted string to display the quote and author
66+
user_is_done = input("enter 'next page' or 'done': ").lower().strip() # Ask the user if they want to continue
67+
page_number += 1 # Incrementing page_number by 1 each loop
68+
if user_is_done == "done": # Taking user inputs "done" and breaking the loop ending the program
69+
break

code/kaceyb/python/lab10/lab_10.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class ATM:
2+
def __init__(self):
3+
self.balance = 0
4+
self.transactions = []
5+
6+
def check_balance(self):
7+
return round(self.balance, 2)
8+
9+
def deposit(self, amount):
10+
self.balance = self.balance + amount
11+
self.transactions.append(f'user deposited ${amount}')
12+
return self.balance
13+
14+
def withdraw(self, amount):
15+
self.balance = self.balance - amount
16+
self.transactions.append(f'user withdrew ${amount}')
17+
return self.balance
18+
19+
def check_withdrawal(self, amount):
20+
if amount > self.balance:
21+
return False
22+
return True
23+
24+
def calc_interest(self):
25+
calc_interest = (self.balance * .1) / 100
26+
return round(calc_interest, 2)
27+
28+
def print_transactions(self):
29+
for transaction in self.transactions:
30+
print(transaction)
31+
32+
33+
34+
35+
36+
37+
38+
atm = ATM() # create an instance of our class
39+
print('Welcome to the ATM')
40+
while True:
41+
command = input('Enter a command: ')
42+
if command == 'balance':
43+
balance = atm.check_balance() # call the check_balance() method
44+
print(f'Your balance is ${balance}')
45+
elif command == 'deposit':
46+
amount = float(input('How much would you like to deposit? '))
47+
atm.deposit(amount) # call the deposit(amount) method
48+
print(f'Deposited ${amount}')
49+
elif command == 'withdraw':
50+
amount = float(input('How much would you like '))
51+
if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method
52+
atm.withdraw(amount) # call the withdraw(amount) method
53+
print(f'Withdrew ${amount}')
54+
else:
55+
print('Insufficient funds')
56+
elif command == 'interest':
57+
amount = atm.calc_interest() # call the calc_interest() method
58+
atm.deposit(amount)
59+
print(f'Accumulated ${amount} in interest')
60+
elif command == 'transactions':
61+
atm.print_transactions()
62+
elif command == 'help':
63+
print('Available commands:')
64+
print('balance - get the current balance')
65+
print('deposit - deposit money')
66+
print('withdraw - withdraw money')
67+
print('interest - accumulate interest')
68+
print('transactions - list of all transactions')
69+
print('exit - exit the program')
70+
71+
elif command == 'exit':
72+
break
73+
else:
74+
print('Command not recognized')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# with open('location.csv', 'w') as file:
2+
# file.write("Hello World")
3+
4+
# # with open(file, 'r') as f:
5+
# # contents = f.readlines()
6+
# # print(contents)
7+
8+
# with open(file, 'r') as f:
9+
# for line in f:
10+
# list.append(line)
11+
12+
# phonebook = {'Dave': '42342', 'Alice': '234234'}
13+
# with open(file, 'w') as location:
14+
# for name, number in location.items():
15+
# line = f'{name}{number}\n'
16+
# location.write(line)
17+
18+
19+
# CSV = comma separated values
20+
21+
# with open('contacts.csv', 'w') as file:
22+
# lines = file.read().split('\n')
23+
# print(lines)
24+
25+
contacts = [
26+
{"name": "matthew", "favorite fruit": "blackberries", "favorite color": "orange"},
27+
{"name": "sam", "favorite fruit": "pineapple", "favorite color": "purple"},
28+
{"name": "teeto", "favorite fruit": "lychee", "favorite color": "brown"},
29+
]
30+
31+
f = open("contacts.csv")
32+
33+
with open("contacts.csv", "r") as contacts:
34+
contacts_data = contacts.read().split("\n")
35+
36+
dict = []
37+
for line in contacts_data:
38+
dict.append(contacts_data)

code/kaceyb/python/notes/lesson06/lesson_09.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,44 @@
44
# def __init__(self, username, email):
55
# self.username = username
66
# self.email = email
7-
7+
88
# bruce = User('criticbruce', '[email protected]')
99

1010
# print(bruce.username)
1111

1212
# SECOND PIECE #
1313

1414
import math
15+
16+
17+
18+
def distance(p1, p2):
19+
dx = p1["x"] - p2["x"]
20+
dy = p1["y"] - p2["y"]
21+
return math.sqrt(dx * dx + dy * dy)
22+
23+
24+
p1 = {"x": 5, "y": 2}
25+
p2 = {"x": 8, "y": 4}
26+
print(distance(p1, p2))
27+
28+
29+
class Point:
30+
def __init__(self, x, y):
31+
self.x = x
32+
self.y = y
33+
34+
def distance(self, p):
35+
dx = self.x - p.x
36+
dy = self.y - p.y
37+
return math.sqrt(dx * dx + dy * dy)
38+
39+
40+
p1 = Point(5, 2) # call the initializer, instantiate the class
41+
42+
p1 = (5, 2)
43+
p2 = Point(8, 4)
44+
1545
def distance(p1, p2):
1646
dx = p1['x'] - p2['x']
1747
dy = p1['y'] - p2['y']
@@ -41,16 +71,13 @@ def distance(self, p):
4171
print(type(p1))
4272
# print(p1.distance(p2))
4373

74+
75+
name = [1, 2, 3]
76+
4477
name = [1,2,3]
78+
4579
print(type(name))
4680
print(name.sort())
4781

4882
number = input("What's your favorite number?: ")
4983
print(type(number))
50-
51-
52-
53-
54-
55-
56-

code/kaceyb/python/notes/lesson06/lesson_11.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World

code/kaceyb/python/notes/lesson06/mini_capstone.py

Whitespace-only changes.

code/kaceyb/python/notes/lesson06/notes.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# with open('example.txt', 'a') as file:
22
# text = file.write('\nMORE TEXT')
3+
4+
# print(text)
35
# print(text)
46

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

1012
# with open('colors.txt') as file:
1113
# colors = file.read()
14+
15+
# colors = file.read().split()
16+
# print(colors)
17+
1218

1319
# colors = file.read().split()
1420
# print(colors)
@@ -17,6 +23,9 @@
1723
# text = file.write()
1824
# print(text)
1925

26+
# import datetime
27+
28+
# read file
2029
# import datetime
2130

2231
#read file
@@ -34,6 +43,11 @@
3443

3544
# with open('phonebook.txt') as file:
3645
# phone_book = file.read()
46+
47+
# phone_book = phone_book.split('\n')
48+
# name = input('Lookup name: ')
49+
50+
3751

3852
# phone_book = phone_book.split('\n')
3953
# name = input('Lookup name: ')
@@ -43,19 +57,27 @@
4357
# if name.lower() in entry.lower():
4458
# print(entry)
4559
# found_entry = True
46-
60+
61+
62+
4763
# if not found_entry:
4864
# print('Contact not found')
4965
# name = input('Enter new contact name: ')
5066
# phone_number = input(f'Enter the number for : {name}')
67+
68+
# phone_book.append(name + " " + phone_number)
69+
70+
# phone_book.sort()
71+
# with open('phonebook2.txt', 'w') as file2:
72+
# file2.write('\n'.join(phone_book))
73+
5174

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

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

58-
5981
# print(type(phone_book))
6082
# print(phone_book)
6183
# def Convert(lst):
@@ -66,4 +88,6 @@
6688
# color = file.read()
6789
# color = color.split('\n')
6890
# color = Convert(color)
69-
# print(color)
91+
# print(color)
92+
93+
# print(color)

code/kaceyb/python/notes/lesson06/notes2.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
# # for category in categories:
2727
# # print(category)
28+
29+
# for i in range(len(categories)):
30+
# print(i, categories[i])
31+
2832

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

4347

4448
import requests
49+
50+
url = "https://ghibliapi.herokuapp.com/films"
51+
4552
url = 'https://ghibliapi.herokuapp.com/films'
4653
response = requests.get(url)
4754
# print(response.text)
4855
data = response.json()
4956
# print(data[0]['title'])
5057
for film in data:
58+
print(film["title"])
59+
print(film["release_date"])
60+
print(film["description"])
61+
62+
print("-" * 10)
5163
print(film['title'])
5264
print(film['release_date'])
5365
print(film['description'])
5466

5567

5668
print('-'*10)
57-

0 commit comments

Comments
 (0)