Skip to content

Commit be2c643

Browse files
committed
2 parents b6b6392 + 5e36d30 commit be2c643

File tree

32 files changed

+1376
-12
lines changed

32 files changed

+1376
-12
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pylyrics3
2+
# https://github.com/jameswenzel/pylyrics3
3+
4+
5+
bon_iver_lyrics = pylyrics3.get_artist_lyrics('bon iver')
6+
7+
print(bon_iver_lyrics)
8+
9+
10+
while True:
11+
artist = input('What artist do you want to look up?')
12+
print(pylyrics3.get_artist_lyrics(artist))
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Lab 1: Turtle
2+
3+
## Explanation
4+
5+
Turtle is a python `module` that allows us to move a virtual turtle around the screen using programming statements. This turtle has a position and a heading. Below are a list of commands, you can more in the [turtle docs](https://docs.python.org/3.6/library/turtle.html).
6+
7+
- `forward(distance)` moves the turtle forward the given number of pixels
8+
- `left(angle)` and `right(angle)` turns the turtle left or right by the given angle (in degrees)
9+
- `color(color_name)` sets the pen's color, which can be `penup()` `penup()` `penup()`
10+
- `penup()` raises the pen, a line won't be drawn when the turtle moves, `pendown()` lowers the pen again
11+
12+
- `setposition(x, y)` moves the turtle to the given position
13+
14+
- `fillcolor(color_name)` sets the fill color, `begin_fill()` indicates you'd like to begin filling in whatever you draw, `end_fill()` actually fills the shape in.
15+
16+
Use these functions to draw a stick figure with a head, body, two arms, and two legs. Once you're done, go through the examples below and create your own drawing.
17+
18+
## Examples
19+
20+
21+
### Drawing a Square
22+
23+
```python
24+
from turtle import *
25+
26+
forward(100)
27+
left(90)
28+
forward(100)
29+
left(90)
30+
forward(100)
31+
left(90)
32+
forward(100)
33+
left(90)
34+
35+
done()
36+
37+
```
38+
39+
### Filling in a Square
40+
41+
```python
42+
from turtle import *
43+
44+
fillcolor('red')
45+
begin_fill()
46+
47+
forward(100)
48+
left(90)
49+
forward(100)
50+
left(90)
51+
forward(100)
52+
left(90)
53+
forward(100)
54+
left(90)
55+
56+
end_fill()
57+
58+
done()
59+
60+
```
61+
62+
### Drawing a Star
63+
64+
```python
65+
from turtle import *
66+
67+
forward(100)
68+
right(144)
69+
forward(100)
70+
right(144)
71+
forward(100)
72+
right(144)
73+
forward(100)
74+
right(144)
75+
forward(100)
76+
77+
done()
78+
79+
```
80+
81+
82+
### Drawing a Square with a Loop
83+
84+
```python
85+
from turtle import *
86+
87+
i = 0
88+
while i < 4:
89+
forward(100)
90+
left(90)
91+
i = i + 1
92+
93+
done()
94+
```
95+
96+
### Drawing a Circle with a Loop
97+
```python
98+
from turtle import *
99+
100+
i = 0
101+
while i < 100:
102+
forward(2)
103+
left(360/100)
104+
i = i + 1
105+
106+
done()
107+
```
108+
109+
### Drawing a Staircase
110+
111+
```python
112+
from turtle import *
113+
114+
i = 0
115+
while i < 4:
116+
forward(100)
117+
left(90)
118+
forward(100)
119+
right(90)
120+
i = i + 1
121+
done()
122+
```
123+
124+
125+
### Filling in a Square
126+
127+
```python
128+
from turtle import *
129+
130+
fillcolor('red')
131+
begin_fill()
132+
133+
forward(100)
134+
left(90)
135+
forward(100)
136+
left(90)
137+
forward(100)
138+
left(90)
139+
forward(100)
140+
left(90)
141+
142+
end_fill()
143+
144+
done()
145+
146+
```
147+
148+
### Draw an N-Sided figure
149+
```python
150+
from turtle import *
151+
152+
edge_length = 100
153+
n_sides = 5
154+
155+
i = 0
156+
while i < n_sides:
157+
forward(edge_length/n_sides)
158+
right(360/n_sides)
159+
i = i + 1
160+
161+
done()
162+
163+
```
164+
165+
166+
### 8-Sided Spiral
167+
168+
```python
169+
from turtle import *
170+
171+
fillcolor('blue')
172+
173+
n_sides = 8
174+
edge_length = 0
175+
176+
i = 0
177+
begin_fill()
178+
while i < 150:
179+
forward(edge_length)
180+
right(360/n_sides)
181+
i = i + 1
182+
edge_length = edge_length + 1
183+
end_fill()
184+
done()
185+
186+
```
187+
188+
### Expanding Star
189+
190+
```python
191+
from turtle import *
192+
193+
edge_length = 0
194+
i = 0
195+
while i < 100:
196+
forward(edge_length)
197+
right(144)
198+
199+
edge_length += 4
200+
201+
done()
202+
```
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
class ATM:
2+
def __init__(self, balance_arg = 0, intrest_rate_arg = .001): #positional arguments. a method. a more flexable way to do it
3+
self.balance = balance_arg #balance_arg are local varable
4+
self.intrest_rate = intrest_rate_arg
5+
self.transactions = []
6+
7+
8+
# def __init__(self): #positional arguments. a method
9+
# self.balance = 0 one way to do it
10+
# self.intrest_rate = .001
11+
12+
def check_balance(self): # going into self to retrieve balance from what you have
13+
return self.balance #Returning is used to return a value from a function and exit the function. To return a value from a function, use the return keyword. and print means display a value dont think it'll exit the function
14+
15+
def deposit(self, amount):
16+
self.balance += amount
17+
self.transactions.append(f'user deposited {amount}')
18+
return self.balance
19+
20+
def check_withdrawal(self, amount): #using self to get balance and amount since thats what we're checking
21+
if self.balance >= amount:
22+
return True
23+
else:
24+
return False
25+
26+
def withdraw(self, amount):
27+
self.balance -= amount
28+
self.transactions.append(f'user withdrew {amount}')
29+
return self.balance
30+
31+
def calc_interest(self):
32+
interest = self.balance * self.intrest_rate * .01
33+
return interest
34+
35+
def print_transactions(self):
36+
for i in self.transactions:
37+
print(i)
38+
return self.transactions
39+
40+
41+
# atm = ATM(5, .001) #putting the values for the initializer.its an object
42+
# # print("atm bal: ", atm.balance) #just for testing but not done in real life
43+
# # print('atm rate: ', atm.intrest_rate)#just for testing but not done in real life
44+
45+
# atm.check_balance() #atm is object and checkbalance is the method access the balance
46+
# # print('calling check_balance method: ', atm.check_balance())
47+
# the_balance = atm.check_balance()
48+
49+
50+
51+
atm = ATM() # create an instance of our class case sensative make the same as the class being called
52+
print('Welcome to the ATM')
53+
while True:
54+
command = input('Enter a command: ')
55+
if command == 'balance':
56+
balance = atm.check_balance() # call the check_balance() method
57+
print(f'Your balance is ${balance}')
58+
elif command == 'deposit':
59+
amount = float(input('How much would you like to deposit? '))
60+
atm.deposit(amount) # call the deposit(amount) method
61+
print(f'Deposited ${amount}')
62+
elif command == 'withdraw':
63+
amount = float(input('How much would you like '))
64+
if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method
65+
atm.withdraw(amount) # call the withdraw(amount) method
66+
print(f'Withdrew ${amount}')
67+
else:
68+
print('Insufficient funds')
69+
elif command == 'interest':
70+
amount = atm.calc_interest() # call the calc_interest() method
71+
atm.deposit(amount)
72+
print(f'Accumulated ${amount} in interest')
73+
elif command == "transactions":
74+
transactions = atm.print_transactions()
75+
print(f'your transaction history is {transactions}')
76+
elif command == 'help':
77+
print('Available commands:')
78+
print('balance - get the current balance')
79+
print('deposit - deposit money')
80+
print('withdraw - withdraw money')
81+
print('interest - accumulate interest')
82+
print('transactions - view transactions')
83+
print('exit - exit the program')
84+
elif command == 'exit':
85+
break
86+
else:
87+
print('Command not recognized')

code/Andy/python/sample.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# f = open('sample.txt')
2+
# contents = f.read()
3+
# print(contents)
4+
5+
f = open('sample.txt')
6+
contents = f.read()
7+
print(contents)
8+
f.close()

code/Andy/python/sample.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world

0 commit comments

Comments
 (0)