Skip to content

Commit

Permalink
Next part of Exercises (20-23) and some upgrades to existing ones
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowalski995 committed Feb 8, 2022
1 parent 0faf7f0 commit 3fe7e9f
Show file tree
Hide file tree
Showing 15 changed files with 20,418 additions and 8 deletions.
1 change: 0 additions & 1 deletion Excercise_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
print("You need ", counter, " guesses to guess the number!")
break
print("Game Over")
#not finished!
4 changes: 2 additions & 2 deletions Exercise_19.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
# print(r_html)
soup = BeautifulSoup(r_html, features="html.parser")

# os.chdir('/home/jakub/PycharmProjects/practise_python/Exercise_18')
# os.chdir('/home/jakub/PycharmProjects/practise_python/Exercise_19')
# x = open('soup', 'wt')
# x.write(soup.prettify())
# x.close()

find = soup.find_all('p') # find all tags with h3

# os.chdir('/home/jakub/PycharmProjects/practise_python/Exercise_18')
# os.chdir('/home/jakub/PycharmProjects/practise_python/Exercise_19')
# x = open('find', 'wt')
# x.write(str(find))
# x.close()
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions Exercise_20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from functions import list_app, bin_se

new_list = []

counter = int(input("How much arguments do want in the list?\n"))

for i in range(0, counter, 1):
element = input("Write list element: ")
new_list.append(element)

number = input("Provide number to check it appearance in the list\n")

print("Answer: ", list_app(new_list, number))
print("Answer: ", bin_se(new_list, number))
23 changes: 23 additions & 0 deletions Exercise_21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import requests
from bs4 import BeautifulSoup
import os

url = 'http://www.vanityfair.com/society/2014/06/monica-lewinsky-humiliation-culture'
r = requests.get(url)
r_html = r.text
soup = BeautifulSoup(r_html, features="html.parser")

find = soup.find_all('p') # find all tags with h3

name = input("Please name the file: \n")
os.chdir('/home/jakub/PycharmProjects/practise_python/Exercise_21')

with open(name, 'wt') as f:
n = len(find) # get len for iteration
for x in range(6, n-5): # 6 and -5 to cut some stuff
f.write(str.strip(find[x].text)) # strip everything non-text

# with open() as f: is an alternative attempt to writing a file
# alternate way is to do: open_file = open ()
# open_file.write()
# open_file.close()
1 change: 1 addition & 0 deletions Exercise_21/interwiev2

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions Exercise_22/Exercise_22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os.path

import requests

# Download a names list file - only first time
if not os.path.isfile('/names.txt'):
url = 'https://www.practicepython.org/assets/nameslist.txt'
r = requests.get(url, allow_redirects=True)
open('names.txt', 'wb').write(r.content)

# Download an images list file - only first time
if not os.path.isfile('/images.txt'):
url = 'https://www.practicepython.org/assets/Training_01.txt'
r = requests.get(url, allow_redirects=True)
open('images.txt', 'wb').write(r.content)

# Counting the names
dict_count = {}
with open('names.txt', 'r') as open_file:
line = open_file.readline()
while line:
line = line.strip()
if line in dict_count:
dict_count[line] += 1
else:
dict_count[line] = 1
line = open_file.readline()
print(dict_count)

# Counting the images categories
dict_count_im = {}
with open('images.txt', 'r') as open_file:
line = open_file.readline()
while line:
line = line[3:-26] # cut 3 chars in front and 26 from back, so it gives us a category name
if line in dict_count_im:
dict_count_im[line] += 1
else:
dict_count_im[line] = 1
line = open_file.readline()
print(dict_count_im)

# dict_count.keys()
# dict_count.values()

# Be careful with looping!

Loading

0 comments on commit 3fe7e9f

Please sign in to comment.