Skip to content

Commit 4659ffd

Browse files
authored
Add files via upload
1 parent c42b1b6 commit 4659ffd

24 files changed

+303
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear [name],
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Aang
2+
Zuko
3+
Appa
4+
Katara
5+
Sokka
6+
Momo
7+
Uncle Iroh
8+
Toph
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Aang,
2+
3+
You are invited to my birthday this Saturday.
4+
5+
Hope you can make it!
6+
7+
Angela
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Aang,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Appa,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Katara,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Momo,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Sokka,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Toph,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Uncle Iroh,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dear Zuko,
2+
3+
You are invited to eat food at my place this Saturday.
4+
5+
Hope you can make it!
6+
7+
Alvi
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#TODO: Create a letter using starting_letter.txt
2+
#for each name in invited_names.txt
3+
#Replace the [name] placeholder with the actual name.
4+
#Save the letters in the folder "ReadyToSend".
5+
6+
#Hint1: This method will help you: https://www.w3schools.com/python/ref_file_readlines.asp
7+
#Hint2: This method will also help you: https://www.w3schools.com/python/ref_string_replace.asp
8+
#Hint3: THis method will help you: https://www.w3schools.com/python/ref_string_strip.asp
9+
10+
11+
12+
13+
with open("Input/Letters/starting_letter.txt") as letter_file:
14+
letter = letter_file.read()
15+
16+
17+
18+
with open("Input/Names/invited_names.txt") as name_file:
19+
i = 0
20+
names = name_file.read().splitlines()
21+
print(names)
22+
for name in names:
23+
with open(f"Output/ReadyToSend/letter_for_{name}.txt", "x") as file:
24+
with open(f"Output/ReadyToSend/letter_for_{name}.txt","a") as final_file:
25+
final_file.write(letter.replace("[name]",name))
26+
27+
28+
29+
30+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
with open("Input/Letters/starting_letter.txt") as letter_file:
2+
# letter_file.read()

day-24/file-handling/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# file = open('my_file.txt')
2+
# contents = file.read()
3+
# print(contents)
4+
# file.close() #if you open the file only via open you have to close it otherwise it eat ram.
5+
6+
# with open('my_file.txt') as file: #This will close file atuomatically
7+
# contents = file.read()
8+
# print(contents)
9+
10+
11+
# with open('my_file.txt', mode = "a") as file: #mode is used to define how you want to write, default mode is read.
12+
# file.write("\n BRrrrrrrrrrrrrrrrrrrrrrruh")
13+
14+
# with open('wow.txt',mode = "w") as file: #if you enter a file name that doesn't exit it will create the file for you
15+
# file.write("brorororororo")
16+

day-24/file-handling/my_file.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BRuh
2+
BRrrrrrrrrrrrrrrrrrrrrrruh
3+
BRrrrrrrrrrrrrrrrrrrrrrruh
4+
BRrrrrrrrrrrrrrrrrrrrrrruh
5+
BRrrrrrrrrrrrrrrrrrrrrrruh
6+
BRrrrrrrrrrrrrrrrrrrrrrruh

day-24/file-handling/wow.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
brorororororo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from turtle import Turtle
2+
import random
3+
4+
5+
class Food(Turtle):
6+
7+
def __init__(self):
8+
super().__init__()
9+
self.shape("circle")
10+
self.penup()
11+
self.shapesize(stretch_len=0.5, stretch_wid=0.5)
12+
self.color("blue")
13+
self.speed("fastest")
14+
self.refresh()
15+
16+
def refresh(self):
17+
random_x = random.randint(-280, 280)
18+
random_y = random.randint(-280, 280)
19+
self.goto(random_x, random_y)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from turtle import Screen
2+
from snake import Snake
3+
from food import Food
4+
from scoreboard import Scoreboard
5+
import time
6+
7+
screen = Screen()
8+
screen.setup(width=600, height=600)
9+
screen.bgcolor("black")
10+
screen.title("My Snake Game")
11+
screen.tracer(0)
12+
13+
snake = Snake()
14+
food = Food()
15+
scoreboard = Scoreboard()
16+
17+
screen.listen()
18+
screen.onkey(snake.up, "Up")
19+
screen.onkey(snake.down, "Down")
20+
screen.onkey(snake.left, "Left")
21+
screen.onkey(snake.right, "Right")
22+
23+
game_is_on = True
24+
while game_is_on:
25+
screen.update()
26+
time.sleep(0.1)
27+
snake.move()
28+
29+
#Detect collision with food.
30+
if snake.head.distance(food) < 15:
31+
food.refresh()
32+
snake.extend()
33+
scoreboard.increase_score()
34+
35+
#Detect collision with wall.
36+
if snake.head.xcor() > 280 or snake.head.xcor() < -280 or snake.head.ycor() > 280 or snake.head.ycor() < -280:
37+
scoreboard.reset()
38+
snake.reset()
39+
40+
#Detect collision with tail.
41+
for segment in snake.segments:
42+
if segment == snake.head:
43+
pass
44+
elif snake.head.distance(segment) < 10:
45+
scoreboard.reset()
46+
snake.reset()
47+
48+
49+
50+
51+
52+
screen.exitonclick()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from turtle import Turtle
2+
ALIGNMENT = "center"
3+
FONT = ("Courier", 20, "normal")
4+
5+
6+
class Scoreboard(Turtle):
7+
8+
def __init__(self):
9+
super().__init__()
10+
self.score = 0
11+
with open ("data.txt") as file:
12+
self.high_score = int(file.read())
13+
self.color("white")
14+
self.penup()
15+
self.goto(0, 270)
16+
self.hideturtle()
17+
self.update_scoreboard()
18+
19+
def update_scoreboard(self):
20+
self.clear()
21+
self.write(f"Score: {self.score} High Score: {self.high_score}" , align=ALIGNMENT, font=FONT)
22+
23+
def reset(self):
24+
if self.score > self.high_score:
25+
self.high_score = self.score
26+
with open("data.txt",mode = "w") as file:
27+
file.write(f"{self.high_score}")
28+
self.score = 0
29+
self.update_scoreboard()
30+
31+
32+
33+
# def game_over(self):
34+
# self.goto(0, 0)
35+
# self.write("GAME OVER", align=ALIGNMENT, font=FONT)
36+
37+
def increase_score(self):
38+
self.score += 1
39+
self.update_scoreboard()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from turtle import Turtle
2+
STARTING_POSITIONS = [(0, 0), (-20, 0), (-40, 0)]
3+
MOVE_DISTANCE = 20
4+
UP = 90
5+
DOWN = 270
6+
LEFT = 180
7+
RIGHT = 0
8+
9+
10+
class Snake:
11+
12+
def __init__(self):
13+
self.segments = []
14+
self.create_snake()
15+
self.head = self.segments[0]
16+
17+
def create_snake(self):
18+
for position in STARTING_POSITIONS:
19+
self.add_segment(position)
20+
21+
def add_segment(self, position):
22+
new_segment = Turtle("square")
23+
new_segment.color("white")
24+
new_segment.penup()
25+
new_segment.goto(position)
26+
self.segments.append(new_segment)
27+
28+
def reset(self):
29+
for seg in self.segments:
30+
seg.goto(1000,1000)
31+
self.segments.clear()
32+
self.create_snake()
33+
self.head = self.segments[0]
34+
35+
def extend(self):
36+
self.add_segment(self.segments[-1].position())
37+
38+
def move(self):
39+
for seg_num in range(len(self.segments) - 1, 0, -1):
40+
new_x = self.segments[seg_num - 1].xcor()
41+
new_y = self.segments[seg_num - 1].ycor()
42+
self.segments[seg_num].goto(new_x, new_y)
43+
self.head.forward(MOVE_DISTANCE)
44+
45+
def up(self):
46+
if self.head.heading() != DOWN:
47+
self.head.setheading(UP)
48+
49+
def down(self):
50+
if self.head.heading() != UP:
51+
self.head.setheading(DOWN)
52+
53+
def left(self):
54+
if self.head.heading() != RIGHT:
55+
self.head.setheading(LEFT)
56+
57+
def right(self):
58+
if self.head.heading() != LEFT:
59+
self.head.setheading(RIGHT)

0 commit comments

Comments
 (0)