diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0c14453a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vscode/extensions.json +SudokuSolver/__pycache__/sudoku.cpython-38.pyc +.idea +pencilSketch/venv/ diff --git a/Compress Image/img_comp.py b/Compress Image/img_comp.py index c44648d7..9cb379ea 100644 --- a/Compress Image/img_comp.py +++ b/Compress Image/img_comp.py @@ -1,16 +1,24 @@ from PIL import Image +import os -def compress_image(default_image=Image.open('original_image.jpg')): - ''' Takes an image file and compress it without losing image quality. ''' +def compress_image(): + ''' Takes an image file and compress it without losing image quality. ''' - ''' If no image file is provided, the default image will be compressed ''' - - # Get image 'width' and 'height' - w, h = default_image.size - # compress image - default_image = default_image.resize((h, w), Image.ANTIALIAS) - # return compressed image - return default_image.save('compressed_image.jpg') + ''' If no image file is provided, the default image will be compressed ''' + try: + image_name = str(input("Enter the name of the image you want to compress: ")) + default_image=Image.open(f'{image_name}') + except FileNotFoundError: + default_image=Image.open('original_image.jpg') + + # Get image 'width' and 'height' + w, h = default_image.size + # Separate the file name from the extension + default_image_name = os.path.splitext(os.path.basename(default_image.filename)) + # compress image + default_image = default_image.resize((w, h), Image.ANTIALIAS) + # return compressed image + return default_image.save('{}_compressed{}'.format(default_image_name[0], default_image_name[1])) # Run -compress_image() \ No newline at end of file +compress_image() diff --git a/DigitalClock/clock.py b/DigitalClock/clock.py index 06440e8a..0a5becc3 100644 --- a/DigitalClock/clock.py +++ b/DigitalClock/clock.py @@ -1,24 +1,31 @@ # import GUI library - Tkinter -from tkinter import * +import tkinter as tk import time -root = Tk() +class Clock: + def __init__(self): + self.master = tk.Tk() -# Label the window to "My Clock" -root.title('My Clock') + def settings(self): + # Label the window to "My Clock" + self.master.title('My Clock') -#Time calculation -def counttime(time1=''): - time2 = time.strftime('%H:%M:%S') - if time2 != time1: - time1 = time2 - clock.config(text=time2) - clock.after(200, counttime) + def widgets(self): + #Time calculation + def counttime(time1=''): + time2 = time.strftime('%H:%M:%S') + if time2 != time1: + time1 = time2 + clock.config(text=time2) + clock.after(200, counttime) + # Create the clock text + clock = tk.Label(self.master, font=('Poppins', 50, 'bold'), background='blue', foreground='white') + clock.pack(anchor='center') + # Clock loop + counttime() + tk.mainloop() -# Create the clock text -clock = Label(root, font=('Poppins', 50, 'bold'), background='blue', foreground='white') -clock.pack(anchor='center') - -# Clock loop -counttime() -mainloop() \ No newline at end of file +if __name__ == '__main__': + my_clock = Clock() + my_clock.settings() + my_clock.widgets() diff --git a/FlaskSimpleCalculator/__pycache__/app.cpython-38.pyc b/FlaskSimpleCalculator/__pycache__/app.cpython-38.pyc index 32434afb..8d47cd5d 100644 Binary files a/FlaskSimpleCalculator/__pycache__/app.cpython-38.pyc and b/FlaskSimpleCalculator/__pycache__/app.cpython-38.pyc differ diff --git a/FlaskSimpleCalculator/__pycache__/handle_calculation.cpython-38.pyc b/FlaskSimpleCalculator/__pycache__/handle_calculation.cpython-38.pyc new file mode 100644 index 00000000..f8ee6f35 Binary files /dev/null and b/FlaskSimpleCalculator/__pycache__/handle_calculation.cpython-38.pyc differ diff --git a/FlaskSimpleCalculator/app.py b/FlaskSimpleCalculator/app.py index c39cc559..c1c2cfae 100644 --- a/FlaskSimpleCalculator/app.py +++ b/FlaskSimpleCalculator/app.py @@ -1,4 +1,5 @@ from flask import Flask, render_template, request +from handle_calculation import calculate app = Flask(__name__) app.config.from_object(__name__) @@ -8,24 +9,12 @@ def welcome(): return render_template('form.html') - @app.route('/result', methods=['POST']) def result(): operand_1 = request.form.get("operand_1", type=int) operand_2 = request.form.get("operand_2", type=int) operator = request.form.get("operator") - if(operand_2 == 0 and operator=='Division'): - result='Invalid_operation' - elif(operator == 'Addition'): - result = operand_1 + operand_2 - elif(operator == 'Subtraction'): - result = operand_1 - operand_2 - elif(operator == 'Multiplication'): - result = operand_1 * operand_2 - elif(operator == 'Division'): - result = operand_1 / operand_2 - else: - result = 'Invalid_Choice' + result = calculate(operand_1, operand_2, operator) entry = result return render_template('result.html', entry=entry) diff --git a/FlaskSimpleCalculator/handle_calculation.py b/FlaskSimpleCalculator/handle_calculation.py new file mode 100644 index 00000000..7a7c8562 --- /dev/null +++ b/FlaskSimpleCalculator/handle_calculation.py @@ -0,0 +1,26 @@ +# handle_calculation.py + +def calculate(operand_1: int, operand_2: int, operator: str) -> int: + """ + calculation between the operands using the operator and returns a value + + Parameters: + + -operand_1: the first given value + -operand_2: the second given value + -operator: used to trigger the calculation + """ + if(operand_2 == 0 and operator=='Division'): + result='Invalid_operation' + elif(operator == 'Addition'): + result = operand_1 + operand_2 + elif(operator == 'Subtraction'): + result = operand_1 - operand_2 + elif(operator == 'Multiplication'): + result = operand_1 * operand_2 + elif(operator == 'Division'): + result = operand_1 / operand_2 + else: + result = 'Invalid_Choice' + + return result diff --git a/FlaskSimpleCalculator/templates/form.html b/FlaskSimpleCalculator/templates/form.html index c142a278..45f94b65 100644 --- a/FlaskSimpleCalculator/templates/form.html +++ b/FlaskSimpleCalculator/templates/form.html @@ -29,25 +29,25 @@