Compare commits

...

5 Commits

31 changed files with 3561 additions and 9 deletions

View File

@ -6,10 +6,11 @@ class Ball(Turtle):
super().__init__()
self.shape("circle")
self.color("white")
self.speed("fastest")
self.pu()
self.move_speed = 0.1
self.angle = random.randint(0,45)
self.angle = 50
self.setheading(self.angle)
print(self.angle)
@ -22,6 +23,6 @@ class Ball(Turtle):
self.setheading(self.angle)
def bounce_paddle(self):
self.angle = -self.angle
self.angle = 180 - self.angle
self.setheading(self.angle)

View File

@ -1,6 +1,8 @@
from turtle import Turtle, Screen
from paddle import Paddle
from ball import Ball
from score import Score
import time
class GameManager():
BOARD_WIDTH=800
@ -21,6 +23,9 @@ class GameManager():
self.right_paddle = Paddle(350)
self.left_paddle = Paddle(-370)
self.right_score = Score(30)
self.left_score = Score(-30)
self.ball = Ball()
def draw_delimiter(self):
@ -44,13 +49,31 @@ class GameManager():
self.control_paddle()
self.ball.move()
if abs(self.ball.xcor()) >= 400:
if self.ball.xcor() > 400:
self.game_on = False
self.left_score.increment()
self.left_score.update()
if self.ball.xcor() < -400:
self.game_on = False
self.right_score.increment()
self.right_score.update()
if self.game_on == False:
self.ball.clear()
self.ball = Ball()
self.right_paddle.reset_position(350)
self.left_paddle.reset_position(-370)
self.game_on = True
if abs(self.ball.ycor()) > 280:
self.ball.bounce_wall()
print(self.ball.ycor())
if (abs(self.ball.xcor() - self.right_paddle.xcor()) <= 20 and abs(self.ball.ycor() - self.right_paddle.ycor()) < 50) or (abs(self.ball.xcor() - self.left_paddle.xcor()) <= 20 and abs(self.ball.ycor() - self.left_paddle.ycor()) < 50):
self.ball.bounce_paddle()
self.ball.move_speed = self.ball.move_speed * 0.1
time.sleep(self.ball.move_speed)
def control_paddle(self):
self.screen.listen()

View File

@ -1,9 +1,7 @@
from game import GameManager
from paddle import Paddle
import time
game = GameManager()
while game.game_on:
while game.game_on == True:
game.game_round()
time.sleep(0.1)
game.screen.exitonclick()

View File

@ -10,6 +10,9 @@ class Paddle(Turtle):
self.pu()
self.teleport(x=x_pos, y=0)
def reset_position(self, x_pos):
self.teleport(x=x_pos, y=0)
def up(self):
self.goto(x=self.xcor(), y=self.ycor()+20)

18
022/score.py Normal file
View File

@ -0,0 +1,18 @@
from turtle import Turtle
class Score(Turtle):
def __init__(self, x_pos):
super().__init__()
self.score = 0
self.color("white")
self.hideturtle()
self.pu()
self.goto(x=x_pos, y=270)
self.write(self.score, move=False, align='center', font=('Arial', 24, 'normal'))
def increment(self):
self.score += 1
def update(self):
self.clear()
self.write(self.score, move=False, align='center', font=('Arial', 24, 'normal'))

43
023/car_manager.py Normal file
View File

@ -0,0 +1,43 @@
import random
from turtle import Turtle
class CarManager:
COLORS = ["red", "orange", "yellow", "green", "blue", "purple"]
STARTING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 10
CAR_GENERATION_PROBABILITY = 5
def __init__(self):
self.cars = []
self.add_car()
def execute_round(self, level):
if self.should_generate_car_on_turn():
self.add_car()
speed = 5 + (level - 1) * 10
self.move(speed)
def should_generate_car_on_turn(self):
return random.randint(1,self.CAR_GENERATION_PROBABILITY) % self.CAR_GENERATION_PROBABILITY == 0
def move(self, speed):
for car in self.cars:
car.goto(x=car.xcor()-speed, y=car.ycor())
def add_car(self):
car = Turtle()
car.color(random.choice(self.COLORS))
car.shape("square")
car.shapesize(stretch_wid=1, stretch_len=2)
car.pu()
car.goto(x=300, y=random.randint(-260, 280))
self.cars.append(car)
def check_collision(self, player):
for car in self.cars:
if abs(player.ycor() - car.ycor()) < 10 and abs(player.xcor() - car.xcor()) < 30:
return True
return False

34
023/main.py Normal file
View File

@ -0,0 +1,34 @@
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
screen = Screen()
screen.setup(width=600, height=600)
screen.tracer(0)
screen.bgcolor("white")
game_is_on = True
player = Player()
scoreboard = Scoreboard()
cars = CarManager()
while game_is_on:
screen.listen()
screen.onkey(player.move_up, "Up")
cars.execute_round(scoreboard.level)
if cars.check_collision(player):
game_is_on = False
scoreboard.game_over()
time.sleep(0.1)
screen.update()
if player.has_won():
player.reset_position()
scoreboard.level += 1
scoreboard.update_score(scoreboard.level)
print("Finished")
screen.exitonclick()

27
023/player.py Normal file
View File

@ -0,0 +1,27 @@
from turtle import Turtle
class Player(Turtle):
STARTING_POSITION = (0, -280)
MOVE_DISTANCE = 10
FINISH_LINE_Y = 280
def __init__(self):
super().__init__()
self.shape("turtle")
self.color("black")
self.pu()
self.setheading(90)
self.goto(self.STARTING_POSITION)
def move_up(self):
self.goto(x=self.xcor(), y=self.ycor() + self.MOVE_DISTANCE)
print(self.ycor())
def has_won(self):
if self.ycor() >= self.FINISH_LINE_Y:
return True
return False
def reset_position(self):
self.clear()
self.goto(self.STARTING_POSITION)

23
023/scoreboard.py Normal file
View File

@ -0,0 +1,23 @@
from turtle import Turtle
class Scoreboard(Turtle):
FONT = ("Courier", 24, "normal")
def __init__(self):
super().__init__()
self.color("black")
self.pu()
self.hideturtle()
self.goto(-280, 260)
self.level = 1
self.update_score(self.level)
def update_score(self, level):
self.clear()
self.write(f"Level: {level}", False, align="left", font=self.FONT)
def game_over(self):
self.goto(0,0)
self.write("GAME OVER", False, align="center", font=self.FONT)

View File

@ -0,0 +1,7 @@
Dear [name],
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,8 @@
Aang
Zuko
Appa
Katara
Sokka
Momo
Uncle Iroh
Toph

20
024/main.py Normal file
View File

@ -0,0 +1,20 @@
#TODO: Create a letter using starting_letter.txt
#for each name in invited_names.txt
#Replace the [name] placeholder with the actual name.
#Save the letters in the folder "ReadyToSend".
#Hint1: This method will help you: https://www.w3schools.com/python/ref_file_readlines.asp
#Hint2: This method will also help you: https://www.w3schools.com/python/ref_string_replace.asp
#Hint3: THis method will help you: https://www.w3schools.com/python/ref_string_strip.asp
with open("input/names/invited_names.txt") as n:
for name in n.readlines():
name = name.strip()
output_letter = ""
with open("input/letters/starting_letter.txt") as l:
for letter_line in l:
output_letter += letter_line.replace("[name]", name)
with open(f"output/ready_to_send/to_{name}.txt", "w") as final:
final.write(output_letter)

View File

@ -0,0 +1,7 @@
Dear Aang,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Aang,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Appa,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Katara,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Momo,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Sokka,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Toph,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Uncle Iroh,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

View File

@ -0,0 +1,7 @@
Dear Zuko,
You are invited to my birthday this Saturday.
Hope you can make it!
Angela

51
025/50_states.csv Normal file
View File

@ -0,0 +1,51 @@
state,x,y
Alabama,139,-77
Alaska,-204,-170
Arizona,-203,-40
Arkansas,57,-53
California,-297,13
Colorado,-112,20
Connecticut,297,96
Delaware,275,42
Florida,220,-145
Georgia,182,-75
Hawaii,-317,-143
Idaho,-216,122
Illinois,95,37
Indiana,133,39
Iowa,38,65
Kansas,-17,5
Kentucky,149,1
Louisiana,59,-114
Maine,319,164
Maryland,288,27
Massachusetts,312,112
Michigan,148,101
Minnesota,23,135
Mississippi,94,-78
Missouri,49,6
Montana,-141,150
Nebraska,-61,66
Nevada,-257,56
New Hampshire,302,127
New Jersey,282,65
New Mexico,-128,-43
New York,236,104
North Carolina,239,-22
North Dakota,-44,158
Ohio,176,52
Oklahoma,-8,-41
Oregon,-278,138
Pennsylvania,238,72
Rhode Island,318,94
South Carolina,218,-51
South Dakota,-44,109
Tennessee,131,-34
Texas,-38,-106
Utah,-189,34
Vermont,282,154
Virginia,234,12
Washington,-257,193
West Virginia,200,20
Wisconsin,83,113
Wyoming,-134,90
1 state x y
2 Alabama 139 -77
3 Alaska -204 -170
4 Arizona -203 -40
5 Arkansas 57 -53
6 California -297 13
7 Colorado -112 20
8 Connecticut 297 96
9 Delaware 275 42
10 Florida 220 -145
11 Georgia 182 -75
12 Hawaii -317 -143
13 Idaho -216 122
14 Illinois 95 37
15 Indiana 133 39
16 Iowa 38 65
17 Kansas -17 5
18 Kentucky 149 1
19 Louisiana 59 -114
20 Maine 319 164
21 Maryland 288 27
22 Massachusetts 312 112
23 Michigan 148 101
24 Minnesota 23 135
25 Mississippi 94 -78
26 Missouri 49 6
27 Montana -141 150
28 Nebraska -61 66
29 Nevada -257 56
30 New Hampshire 302 127
31 New Jersey 282 65
32 New Mexico -128 -43
33 New York 236 104
34 North Carolina 239 -22
35 North Dakota -44 158
36 Ohio 176 52
37 Oklahoma -8 -41
38 Oregon -278 138
39 Pennsylvania 238 72
40 Rhode Island 318 94
41 South Carolina 218 -51
42 South Dakota -44 109
43 Tennessee 131 -34
44 Texas -38 -106
45 Utah -189 34
46 Vermont 282 154
47 Virginia 234 12
48 Washington -257 193
49 West Virginia 200 20
50 Wisconsin 83 113
51 Wyoming -134 90

BIN
025/blank_states_img.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

52
025/main.py Normal file
View File

@ -0,0 +1,52 @@
from turtle import Turtle, Screen
import pandas as pd
FONT = ("Courier", 14, "normal")
screen = Screen()
screen.setup(725,491)
screen.bgpic('blank_states_img.gif')
screen.tracer(0)
data = pd.read_csv("50_states.csv")
# state, x, y
game_on = True
states_remaining = len(data)
found_states = []
while len(found_states) < 50:
guess = str(screen.textinput(f"{states_remaining} states to find", "Find a state:"))
if guess == "None":
missing_states = [ s for s in data.states if s not in found_states ]
output = pd.DataFrame(missing_states)
output.to_csv("missing_states.csv")
exit()
state = data[data.state == guess.title()]
# if the subset is not empty, it means the state is in the list
if len(state) > 0:
x_pos = state.x.item() #state.iloc[0]["x"]
y_pos = state.y.item() #state.iloc[0]["y"]
state_name = state.iloc[0]["state"]
if state_name in found_states:
continue
states_remaining -= 1
found_states.append(state_name)
text = Turtle()
text.pu()
text.color("black")
text.hideturtle()
text.goto(x_pos, y_pos)
text.write(state_name, align="center", font=FONT)
screen.update()
screen.mainloop()

48
025/missing_states.csv Normal file
View File

@ -0,0 +1,48 @@
Alabama
Alaska
Arkansas
California
Colorado
Connecticut
Delaware
Florida
Georgia
Hawaii
Idaho
Illinois
Indiana
Iowa
Kansas
Kentucky
Louisiana
Maine
Maryland
Massachusetts
Michigan
Minnesota
Mississippi
Missouri
Montana
Nebraska
Nevada
New Hampshire
New Jersey
New Mexico
New York
North Carolina
North Dakota
Oklahoma
Oregon
Pennsylvania
Rhode Island
South Carolina
South Dakota
Tennessee
Texas
Utah
Vermont
Virginia
Washington
West Virginia
Wisconsin
Wyoming
1 Alabama
2 Alaska
3 Arkansas
4 California
5 Colorado
6 Connecticut
7 Delaware
8 Florida
9 Georgia
10 Hawaii
11 Idaho
12 Illinois
13 Indiana
14 Iowa
15 Kansas
16 Kentucky
17 Louisiana
18 Maine
19 Maryland
20 Massachusetts
21 Michigan
22 Minnesota
23 Mississippi
24 Missouri
25 Montana
26 Nebraska
27 Nevada
28 New Hampshire
29 New Jersey
30 New Mexico
31 New York
32 North Carolina
33 North Dakota
34 Oklahoma
35 Oregon
36 Pennsylvania
37 Rhode Island
38 South Carolina
39 South Dakota
40 Tennessee
41 Texas
42 Utah
43 Vermont
44 Virginia
45 Washington
46 West Virginia
47 Wisconsin
48 Wyoming

3024
025/squirrels.csv Normal file

File diff suppressed because it is too large Load Diff

54
025/task.py Normal file
View File

@ -0,0 +1,54 @@
# data = []
# with open("weather_data.csv") as f:
# for line in f.readlines():
# data.append(line.strip().split(','))
# print(data)
# ------------------------------------------------------------------------
# import csv
# temperatures = []
# with open("weather_data.csv") as f:
# reader = csv.reader(f)
# next(reader)
# for row in reader:
# temperatures.append(int(row[1]))
# print(temperatures)
# ------------------------------------------------------------------------
# import pandas as pd
# data = pd.read_csv("weather_data.csv", delimiter=",")
# print(data["temp"].mean())
# print(data["temp"].max())
# output = data[data.temp == data.temp.max()]
# print(output)
# ------------------------------------------------------------------------
import pandas as pd
data = pd.read_csv("squirrels.csv")
colors = data["Primary Fur Color"].unique()
output_colors = []
output_count = []
for color in colors:
if type(color) != str:
continue
count = len(data[data["Primary Fur Color"] == color])
output_colors.append(color)
output_count.append(count)
output = {"color": output_colors, "count": output_count}
df = pd.DataFrame(output)
print(df.to_csv(index=False))

8
025/weather_data.csv Normal file
View File

@ -0,0 +1,8 @@
day,temp,condition
Monday,12,Sunny
Tuesday,14,Rain
Wednesday,15,Rain
Thursday,14,Cloudy
Friday,21,Sunny
Saturday,22,Sunny
Sunday,24,Sunny
1 day temp condition
2 Monday 12 Sunny
3 Tuesday 14 Rain
4 Wednesday 15 Rain
5 Thursday 14 Cloudy
6 Friday 21 Sunny
7 Saturday 22 Sunny
8 Sunday 24 Sunny

15
026/main.py Normal file
View File

@ -0,0 +1,15 @@
import pandas as pd
# Keyword Method with iterrows()
# {new_key:new_value for (index, row) in df.iterrows()}
#TODO 1. Create a dictionary in this format:
# {"A": "Alfa", "B": "Bravo"}
data = pd.read_csv("nato_phonetic_alphabet.csv")
dict = { row.letter:row.code for (index, row) in data.iterrows() }
#TODO 2. Create a list of the phonetic code words from a word that the user inputs.
input = list(input("Which word do you want to spell?\n"))
print([ dict[letter.upper()] for letter in input])

View File

@ -0,0 +1,27 @@
letter,code
A,Alfa
B,Bravo
C,Charlie
D,Delta
E,Echo
F,Foxtrot
G,Golf
H,Hotel
I,India
J,Juliet
K,Kilo
L,Lima
M,Mike
N,November
O,Oscar
P,Papa
Q,Quebec
R,Romeo
S,Sierra
T,Tango
U,Uniform
V,Victor
W,Whiskey
X,X-ray
Y,Yankee
Z,Zulu
1 letter code
2 A Alfa
3 B Bravo
4 C Charlie
5 D Delta
6 E Echo
7 F Foxtrot
8 G Golf
9 H Hotel
10 I India
11 J Juliet
12 K Kilo
13 L Lima
14 M Mike
15 N November
16 O Oscar
17 P Papa
18 Q Quebec
19 R Romeo
20 S Sierra
21 T Tango
22 U Uniform
23 V Victor
24 W Whiskey
25 X X-ray
26 Y Yankee
27 Z Zulu

5
026/task.py Normal file
View File

@ -0,0 +1,5 @@
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
new_numbers = [ n for n in numbers if n % 2 == 1 ]
print(new_numbers)