-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next part of Exercises (20-23) and some upgrades to existing ones
- Loading branch information
1 parent
0faf7f0
commit 3fe7e9f
Showing
15 changed files
with
20,418 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,3 @@ | |
print("You need ", counter, " guesses to guess the number!") | ||
break | ||
print("Game Over") | ||
#not finished! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
|
Oops, something went wrong.