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
11 changes: 11 additions & 0 deletions bonus/bonus10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
try:
width = float(input('Enter the rectangle width: '))
length = float(input('Enter the rectangle length: '))

if width == length:
exit("It shouldn't be a square area calculation")

area = width * length
print(area)
except ValueError:
print("It's expected numbers to be multiplied" )
12 changes: 12 additions & 0 deletions bonus/bonus11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def get_average():
with open('files/data.txt', 'r') as file:
data = file.readlines()

values = data[1:]
values = [float(i) for i in values]

average_local = sum(values) / len(values)
return average_local

average = get_average()
print(average)
17 changes: 17 additions & 0 deletions bonus/bonus12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
feet_inches = input('Enter feet and inches: ')

def convert(feet_inches):
parts = feet_inches.split(' ')
feet = float(parts[0])
inches = float(parts[1])

meters = feet * 0.3048 + inches * 0.0254
return meters


result = convert(feet_inches)

if result < 1:
print('Kid is too small.')
else:
print('kid can use the slide.')
23 changes: 23 additions & 0 deletions bonus/bonus13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
feet_inches = input('Enter feet and inches: ')


def parse(feetinches):
parts = feetinches.split(' ')
feet = float(parts[0])
inches = float(parts[1])
return feet, inches


def convert(feet, inches):
meters = feet * 0.3048 + inches * 0.0254
return meters


f, i = parse(feet_inches)
print('fi', f, i)
result = convert(f, i)

if result < 1:
print('Kid is too small.')
else:
print('kid can use the slide.')
15 changes: 15 additions & 0 deletions bonus/bonus14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from bonus.converters14 import convert
from bonus.parsers14 import parse

feet_inches = input('Enter feet and inches: ')

parsed = parse(feet_inches)

result = convert(parsed['feet'], parsed['inches'])

print(f"{parsed['feet']} feet and {parsed['inches']} is equals to {result}")

if result < 1:
print('Kid is too small.')
else:
print('kid can use the slide.')
15 changes: 15 additions & 0 deletions bonus/bonus15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from bonus.converters14 import convert
from bonus.parsers14 import parse

feet_inches = input('Enter feet and inches: ')

parsed = parse(feet_inches)

result = convert(parsed['feet'], parsed['inches'])

print(f"{parsed['feet']} feet and {parsed['inches']} is equals to {result}")

if result < 1:
print('Kid is too small.')
else:
print('kid can use the slide.')
30 changes: 30 additions & 0 deletions bonus/bonus16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import FreeSimpleGUI as fsg
from zip_creator import make_archive

label1 = fsg.Text("Select files to compress")
input1 = fsg.Input()
choose_button1 = fsg.FilesBrowse("Choose", key="files")

label2 = fsg.Text("Select destination folder")
input2 = fsg.Input()
choose_button2 = fsg.FolderBrowse("Choose", key="folder")

compress_button = fsg.Button("Compress")
output_label = fsg.Text(key="output", text_color="#000022")

window = fsg.Window("File Compressor",
layout=[[label1, input1, choose_button1],
[label2, input2, choose_button2],
[compress_button, output_label]])

while True:
event, values = window.read()
if event == fsg.WIN_CLOSED:
break
filepaths = values["files"].split(";")
folder = values["folder"]
make_archive(filepaths, folder)
window["output"].update(value="Compression completed!")


window.close()
47 changes: 47 additions & 0 deletions bonus/bonus18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import FreeSimpleGUI as fsg
from zip_extractor import extract_archive

fsg.theme('Black')

label1 = fsg.Text("Select archive:")
input1 = fsg.Input()
choose_button1 = fsg.FileBrowse("Choose", key="archive")

label2 = fsg.Text("Select dest. dir.:")
input2 = fsg.Input()
choose_button2 = fsg.FileBrowse("Choose", key="folder")

extract_button = fsg.Button("Extract")
output_label = fsg.Text(key="output", text_color="green")

window = fsg.Window("Archive Extractor",
layout=[[label1, input1, choose_button1],
[label2, input2, choose_button2],
[extract_button, output_label]])

while True:
event, values = window.read()

match event:
case fsg.WIN_CLOSED:
break

case "Extract":
archivepath = values["archive"]
dest_dir = values["folder"]

if archivepath and dest_dir:
try:
extract_archive(archivepath, dest_dir)
window["output"].update(value="Extraction Completed!", text_color="green")
except FileNotFoundError:
window["output"].update(value="Error: Archive file not found.", text_color="red")
except PermissionError:
window["output"].update(value="Error: Permission denied.", text_color="red")
except Exception as e:
window["output"].update(value=f"Error: {e}", text_color="red")
else:
window["output"].update(value="Please select both archive and destination directory.",
text_color="red")

window.close()
27 changes: 27 additions & 0 deletions bonus/bonus9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
password = input('Enter new password ')

result = []

if len(password) >= 8:
result.append(True)
else:
result.append(False)

digit = False
for i in password:
if i.isdigit():
digit = True

result.append(digit)

uppercase = False
for i in password:
if i.isupper():
uppercase = True

result.append(digit)

if all(result):
print('Strong Password')
else:
print('Weak Password')
Binary file added bonus/compressed.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions bonus/converters14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def convert(feet, inches):
meters = feet * 0.3048 + inches * 0.0254
return meters
7 changes: 7 additions & 0 deletions bonus/dest/bonus1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
print("Don't enter a title here")

text = input('Enter a title: ')

length = len(text)

print('Length of:',length)
6 changes: 6 additions & 0 deletions bonus/dest/bonus2.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
x = 1

while x <= 6:
print(x)
x = x + 1

Binary file added bonus/dest/compressed.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions bonus/parsers14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def parse(feetinches):
parts = feetinches.split(' ')
feet = float(parts[0])
inches = float(parts[1])
return {'feet': feet, 'inches': inches}
6 changes: 6 additions & 0 deletions bonus/questions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"question_text":"What are dolphins?",
"alternatives": ["Amphibians", "Fish", "Mammals", "Birds"],
"correct_answer":3},
{"question_text":"What occupies most of the Earth's surface?",
"alternatives": ["Land", "Water"],
"correct_answer":2}]
13 changes: 13 additions & 0 deletions bonus/zip_creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import zipfile
import pathlib

def make_archive(filepaths, dest_dir):
dest_path = pathlib.Path(dest_dir, "compressed.zip")
with zipfile.ZipFile(dest_path, 'w') as archive:
for filepath in filepaths:
filepath = pathlib.Path(filepath)
archive.write(filepath, arcname=filepath.name)


if __name__ == "__main__":
make_archive(filepaths=["bonus1.py", "bonus2.2.py"], dest_dir="dest")
10 changes: 10 additions & 0 deletions bonus/zip_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import zipfile


def extract_archive(archivepath, dest_dir):
with zipfile.ZipFile(archivepath, 'r') as archive:
archive.extractall(dest_dir)

# if __name__ == "__main__":
# extract_archive(r"D:\Python\PythonProject\ToDoList\bonus\compressed.zip",
# r"D:\Python\PythonProject\ToDoList\bonus\dest")
57 changes: 57 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# from modules.functions import get_todos, write_todos "not necessary functions. before get_todos and write_todos", but requires __init__.py inside modules directory
import time

from modules import functions
import time

now = time.strftime('%b %d, %Y %H:%M:%S')
print("It's", now)

while True:
user_action = input('Type add, show or display, edit, complete, or exit: ')
user_action = user_action.strip()

if user_action.startswith('add'):
todo = user_action[4:]
todos = functions.get_todos()
todos.append(todo.capitalize() + '\n')
functions.write_todos(todos)

elif user_action.startswith('show') or user_action.startswith('display'):
todos = functions.get_todos()
for index, item in enumerate(todos):
item = item.strip('\n').capitalize()
print(f"{index + 1}. {item}")

elif user_action.startswith('edit'):
try:
number = int(user_action[5:])
number = number - 1
todos = functions.get_todos()
new_todo = input('Enter new todo: ')
todos[number] = new_todo + '\n'
functions.write_todos(todos)
except ValueError:
print('Expected the number of the todo instead of a name.')
continue

elif user_action.startswith('complete'):
try:
number = int(user_action[9:])
todos = functions.get_todos()
index = number - 1
todo_to_remove = todos[index].strip('\n')
todos.pop(index)
functions.write_todos(todos)
print(f'Todo {todo_to_remove} was removed from the list.')
except IndexError:
print("There's no item with that number.")
continue

elif user_action.startswith('exit'):
break

else:
print('Hey! You entered an unknown command.')

print('Bye!')
7 changes: 7 additions & 0 deletions experiments/e1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import glob

myfiles = glob.glob("../files/*.txt")

for filepath in myfiles:
with open(filepath, 'r') as file:
print(file.read())
10 changes: 10 additions & 0 deletions experiments/e2_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import csv

with open("weather.csv", 'r') as file:
data = list(csv.reader(file))

city = input("Enter a city: ")

for row in data[1:]:
if row[0] == city:
print(row[1])
3 changes: 3 additions & 0 deletions experiments/e3_1.oy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import shutil

shutil.make_archive("output", "zip", "../files")
10 changes: 10 additions & 0 deletions experiments/e4_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import csv

with open("weather.csv", 'r') as file:
data = list(csv.reader(file))

city = input("Enter a city: ")

for row in data[1:]:
if row[0] == city:
print(row[1])
Empty file added experiments/output.zip
Empty file.
3 changes: 3 additions & 0 deletions experiments/weather.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Station","Temperature"
"Kuala Lumpur","45"
"New York","20"
2 changes: 2 additions & 0 deletions files/todos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
new todo

Loading