Skip to content

Commit 753003b

Browse files
committed
merge~4
1 parent a1ada5f commit 753003b

File tree

23 files changed

+631
-0
lines changed

23 files changed

+631
-0
lines changed

Turtle Crossingm Capstone/car_manager.py

Whitespace-only changes.

Turtle Crossingm Capstone/player.py

Whitespace-only changes.

Turtle Crossingm Capstone/score.py

Whitespace-only changes.

Turtle Graphics/main.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import turtle as t
2+
from turtle import Screen
3+
import random
4+
5+
6+
its = t.Turtle()
7+
8+
9+
# its_turtle.shape("arrow")
10+
# its_turtle.color("black")
11+
# its_turtle.down()
12+
# its_turtle.right(90)
13+
# its_turtle.forward(100)
14+
# its_turtle.right(90)
15+
# its_turtle.forward(100)
16+
# its_turtle.right(90)
17+
# its_turtle.forward(100)
18+
# its_turtle.right(90)
19+
# its_turtle.forward
20+
21+
# for i in range(9):
22+
# its.forward(5)
23+
# its.penup()
24+
# its.forward(8)
25+
# # its.pendown()
26+
# its.speed(300)
27+
# for i in range(3):
28+
# its.forward(100)
29+
# its.right(120)
30+
#
31+
# for i in range(4):
32+
# its.forward(100)
33+
# its.right(90)
34+
#
35+
# for i in range(6):
36+
# its.forward(100)
37+
# its.right(60)
38+
#
39+
# for i in range(8):
40+
# its.forward(100)
41+
# its.right(45)
42+
#
43+
# for i in range(9):
44+
# its.forward(100)
45+
# its.right(40)
46+
# its.color("violet")
47+
# for i in range(10):
48+
# its.forward(100)
49+
# its.right(36)
50+
# its.color("red")
51+
# its.speed(3000)
52+
53+
# def shape(sides):
54+
# angle = 360/sides
55+
# for i in range(sides):
56+
# its.forward(100)
57+
# its.right(angle)
58+
#
59+
# for j in range(3,11):
60+
# shape(j)
61+
62+
# colors = ["purple", "blue", "green", "black","yellow", "sunflower"]
63+
#
64+
# direction=[0,90,180,270]
65+
#
66+
# its.pensize(15)
67+
#
68+
# for i in range(30):
69+
# its.color(random.choice(colors))
70+
# its.forward(30)
71+
# its.setheading(random.choice(direction))
72+
73+
t.colormode(255)
74+
def colorm():
75+
r = random.randint(0, 255)
76+
g = random.randint(0, 255)
77+
b = random.randint(0, 255)
78+
c = (r, g, b)
79+
return c
80+
colorm()
81+
its.speed(500)
82+
for i in range(40):
83+
current = its.heading()
84+
its.width(1)
85+
its.color(colorm())
86+
its.left(10)
87+
its.circle(130)
88+
its.setheading(current+10)
89+
90+
screen = Screen()
91+
screen.exitonclick()

Turtle Race Project/main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from turtle import Turtle, Screen
2+
import random
3+
4+
screen = Screen()
5+
6+
# def factor():
7+
# its.forward(50)
8+
# def backward():
9+
# its.backward(50)
10+
# def left_turn():
11+
# head_direction= its.heading() + 10
12+
# its.setheading(head_direction)
13+
# def right_turn():
14+
# head_direction = its.heading() - 10
15+
# its.setheading(head_direction)
16+
17+
# screen.listen()
18+
# screen.onkey(key="space", fun=factor)
19+
# screen.onkey(key="q", fun=backward)
20+
# screen.onkey(key="w", fun=left_turn)
21+
# screen.onkey(key="e",fun=right_turn)
22+
is_race_on = False
23+
screen.setup(height=400, width=600)
24+
user_bet = screen.textinput(title="who will win the race", prompt="which color you choose")
25+
rainbow_color = ["red", "yellow", "green", "blue", "purple", "orange"]
26+
y_position = [0, -62, -124, 62, 124, 180]
27+
all_turtles = []
28+
for turtle_index in range(0, 6):
29+
its = Turtle(shape="turtle")
30+
its.color(rainbow_color[turtle_index])
31+
its.penup()
32+
its.goto(x=-270, y=y_position[turtle_index])
33+
all_turtles.append(its)
34+
35+
if user_bet:
36+
is_race_on = True
37+
38+
while is_race_on:
39+
for turtle in all_turtles:
40+
if turtle.xcor() > 270:
41+
is_race_on = False
42+
winning_color = turtle.pencolor()
43+
if winning_color == user_bet:
44+
print(f"you won the {winning_color} turtle won ")
45+
else:
46+
print(f"you lost ! The {winning_color} turtle won")
47+
48+
random_distance = random.randint(0, 10)
49+
turtle.forward(random_distance)
50+
51+
screen.exitonclick()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## 100 Movies that You Must Watch
2+
3+
# Objective
4+
5+
Scrape the top 100 movies of all time from a website. Generate a text file called `movies.txt` that lists the movie titles in ascending order (starting from 1).
6+
The result should look something like this:
7+
8+
```
9+
1) The Godfather
10+
2) The Empire Strikes Back
11+
3) The Dark Knight
12+
4) The Shawshank Redemption
13+
... and so on
14+
```
15+
The central idea behind this project is to be able to use BeautifulSoup to obtain some data - like movie titles - from a website like Empire's (or from, say Timeout or Stacker that have curated similar lists).
16+
17+
### ⚠️ Important: Use the Internet Archive's URL
18+
19+
Since websites change very frequently, **use this link**
20+
```
21+
URL = "https://web.archive.org/web/20200518073855/https://www.empireonline.com/movies/features/best-movies-2/"
22+
```
23+
from the Internet Archive's Wayback machine. That way your work will match the solution video.
24+
25+
26+
# Solution
27+
28+
You can find the code from my walkthrough and solution as a downloadable .zip file in the course resources for this lesson.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
1) The Godfather
2+
2) The Empire Strikes Back
3+
3) The Dark Knight
4+
4) The Shawshank Redemption
5+
5) Pulp Fiction
6+
6) Goodfellas
7+
7) Raiders Of The Lost Ark
8+
8) Jaws
9+
9) Star Wars
10+
10) The Lord Of The Rings: The Fellowship Of The Ring
11+
11) Back To The Future
12+
12: The Godfather Part II
13+
13) Blade Runner
14+
14) Alien
15+
15) Aliens
16+
16) The Lord Of The Rings: The Return Of The King
17+
17) Fight Club
18+
18) Inception
19+
19) Jurassic Park
20+
20) Die Hard
21+
21) 2001: A Space Odyssey
22+
22) Apocalypse Now
23+
23) The Lord Of The Rings: The Two Towers
24+
24) The Matrix
25+
25) Terminator 2: Judgment Day
26+
26) Heat
27+
27) The Good, The Bad And The Ugly
28+
28) Casablanca
29+
29) The Big Lebowski
30+
30) Seven
31+
31) Taxi Driver
32+
32) The Usual Suspects
33+
33) Schindler's List
34+
34) Guardians Of The Galaxy
35+
35) The Shining
36+
36) The Departed
37+
37) The Thing
38+
38) Mad Max: Fury Road
39+
39) Saving Private Ryan
40+
40) 12 Angry Men
41+
41) Eternal Sunshine Of The Spotless Mind
42+
42) There Will Be Blood
43+
43) One Flew Over The Cuckoo's Nest
44+
44) Gladiator
45+
45) Drive
46+
46) Citizen Kane
47+
47) Interstellar
48+
48) The Silence Of The Lambs
49+
49) Trainspotting
50+
50) Lawrence Of Arabia
51+
51) It's A Wonderful Life
52+
52) Once Upon A Time In The West
53+
53) Psycho
54+
54) Vertigo
55+
55) Pan's Labyrinth
56+
56) Reservoir Dogs
57+
57) Whiplash
58+
58) Inglourious Basterds
59+
59) E.T. – The Extra Terrestrial
60+
60) American Beauty
61+
61) Forrest Gump
62+
62) La La Land
63+
63) Donnie Darko
64+
64) L.A. Confidential
65+
65) Avengers Assemble
66+
66) Return Of The Jedi
67+
67) Memento
68+
68) Ghostbusters
69+
69) Singin' In The Rain
70+
70) The Lion King
71+
71) Hot Fuzz
72+
72) Rear Window
73+
73) Seven Samurai
74+
74) Mulholland Dr.
75+
75) Fargo
76+
76) A Clockwork Orange
77+
77) Toy Story
78+
78) Oldboy
79+
79) Captain America: Civil War
80+
15) Spirited Away
81+
81) The Social Network
82+
82) Some Like It Hot
83+
83) True Romance
84+
84) Rocky
85+
85) Léon
86+
86) Indiana Jones And The Last Crusade
87+
87) Predator
88+
88) The Exorcist
89+
89) Shaun Of The Dead
90+
90) No Country For Old Men
91+
91) The Prestige
92+
92) The Terminator
93+
93) The Princess Bride
94+
94) Lost In Translation
95+
95) Arrival
96+
96) Good Will Hunting
97+
97) Titanic
98+
98) Amelie
99+
99) Raging Bull
100+
100) Stand By Me
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
URL = "https://web.archive.org/web/20200518073855/https://www.empireonline.com/movies/features/best-movies-2/"
5+
6+
try:
7+
response = requests.get(URL)
8+
response.raise_for_status()
9+
except requests.exceptions.RequestException as e:
10+
print(f"Request failed: {e}")
11+
exit()
12+
13+
soup = BeautifulSoup(response.text, "html.parser")
14+
15+
all_movies_data = soup.find_all("h3", class_="title")
16+
17+
movies_name = [movie.get_text(strip=True) for movie in all_movies_data]
18+
movies = movies_name[::-1]
19+
20+
with open("file.txt", "w", encoding="utf-8") as file:
21+
for movie in movies:
22+
file.write(f"{movie}\n")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from bs4 import BeautifulSoup
2+
3+
with open("website.html", 'r') as file:
4+
contents = file.read()
5+
# print(contents)
6+
7+
soup = BeautifulSoup(contents, 'html.parser')
8+
all_anchor_tab = soup.find_all(name='a')
9+
# print(all_anchor_tab)
10+
11+
# print all link present a tag
12+
for anchor in all_anchor_tab:
13+
# print(anchor['href'])
14+
print(anchor.get("href"))
15+
16+
# heading = soup.find_all(name='h1',id="name")
17+
# print(heading)
18+
19+
section_heading = soup.find_all(name='h3',class_="heading")
20+
print(section_heading)
21+
22+
# name = soup.select_one('#name').text
23+
# print(name)
24+
#
25+
# heading = soup.select('.heading')
26+
# print(heading)
27+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from bs4 import BeautifulSoup
2+
import requests
3+
4+
response = requests.get("https://appbrewery.github.io/news.ycombinator.com/")
5+
yc_web_page = response.text
6+
7+
soup = BeautifulSoup(yc_web_page, 'html.parser')
8+
9+
# Get all article links
10+
articles = soup.find_all(name='a', class_='storylink')
11+
12+
article_text = []
13+
article_url = []
14+
15+
for article in articles:
16+
text = article.get_text()
17+
article_text.append(text)
18+
url = article.get("href")
19+
article_url.append(url)
20+
21+
# Get upvotes
22+
article_upvote = [int(score.getText().split()[0]) for score in soup.find_all(name='span', class_="score")]
23+
24+
print(article_text)
25+
print(article_url)
26+
print(article_upvote)
27+
max_val=article_upvote.index(max(article_upvote))
28+
print("\n")
29+
print("Print the maximum score of article upvote")
30+
print(f"Article Text : {article_text[max_val]} , With url link : {article_url[max_val]} with total upvotes : {article_upvote[max_val]}")
31+
32+
# for split value of upvote
33+
# no_upvote = []
34+
#
35+
# for i in range(len(article_upvote)):
36+
# article_upvote1 = article_upvote[0].split(' ')[0]
37+
# no_upvote.append(article_upvote1)
38+
# print(no_upvote)

0 commit comments

Comments
 (0)