Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@
Your task is to clone this repository, create a new branch, fix all the issues and bad practises, add file with list of all the changes and explanations why they are wrong. Then create a pull request with your branch, add your teacher as reviewer.

(As this project is full of bad practises please do not use it as an example. It's for educational purposes only.)

1. Global variables in file87.py
2. Import in weird places in file157.py
3. Too long and unreadable variable names in the 157.py file, which describe too detailed the operation of the variables
4. Unintuitive files name
5. Variable name like "b = 0, c = 1" can only by if we provide a descriptions.
6. Unnesserly fragment: yield 'finished'
7. "__init__" in class PiContainer have to by declarate in this way:
"def __init__(self, a = None):
self.a = a if a is not None else []"
, because we will by able to create new memory space for the new object.
8. More description, the best to use English language
9. When we imprt something the best way is to define what we use from the library
10. Use 'pathlib' to manipulate paths, as this will reduce the chance of errors when opening our program in another OS
30 changes: 0 additions & 30 deletions file157.py

This file was deleted.

35 changes: 0 additions & 35 deletions file87.py

This file was deleted.

42 changes: 42 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class PiContainer:
def __init__(self, a = None):
self.a = a if a is not None else []

def mth(self, x):
if isinstance(x, list):
self.a += x
else:
self.a.append(x)

# Calculate pi value
def calculatePi(x):

'''
Wzór:
b: Opis zmiennej b
c: Opis zmiennej c

miejsce na wzór

dodatkowe informacje
'''

b = 0
c = 1
for hello in range(x):
if hello % 2 == 0:
b += 4 / c
else:
b -= 4 / c
c += 2
yield b

# Printing element with preamble
def printElements(pi):
for x in pi.a:
print(f"Next element: {x}")

# Printing only values
def enumarate(pi):
for x in pi.a:
print(x)
36 changes: 36 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from functions import calculatePi, PiContainer, enumarate, printElements
import pathlib as Path

if __name__ == "__main__":
try:
myPi01 = PiContainer()
myPi02 = PiContainer()
myPi03 = PiContainer()
piGen01 = calculatePi(5)

for _ in range(5):
myPi01.mth(next(piGen01))

except Exception as e:
print(f'Something went horribly wrong: {e}')

piGen02 = calculatePi(194)

for _ in range(23):
myPi02.mth(next(piGen02))

piGen03 = calculatePi(6)
myPi03.mth([i for i in list(piGen03)])

print(f'My first pi: {printElements(myPi01)}')
print(f'My second pi: {enumarate(myPi02)}')
print(f'My third pi: {myPi03.a}')

# Specify the file path
file_path = Path('some-file.txt')

# Writing to a file
with file_path.open('w') as new_file:
new_file.write(f'My best pi: {myPi03.a[-2]}')