Skip to content

Instantly share code, notes, and snippets.

@matt-berseth
matt-berseth / bank_app.py
Created April 9, 2024 10:03
bank_app.py
import tkinter as tk
from tkinter import messagebox, ttk
import datetime
class BankAccount:
def __init__(self):
self.balance = 0
self.load_balance()
self.transaction_history = []
self.load_transactions()
@matt-berseth
matt-berseth / tkinter_ui.py
Created April 7, 2024 13:06
tkinter_ui.py
import tkinter as tk
def on_button_click():
# Get the text from the input text box and set it to the output label
user_input = input_text_box.get()
output_label.config(text="You entered: " + user_input)
# Create the main window
window = tk.Tk()
window.title("Simple Tkinter UI")
@matt-berseth
matt-berseth / bank_accounts.py
Last active April 4, 2024 11:08
bank_accounts.py
class BankAccount:
def __init__(self, owner, account_number, balance=0):
self.owner = owner
self.balance = balance
self.account_number = account_number
def deposit(self, amount):
if amount > 0:
self.balance += amount
@matt-berseth
matt-berseth / polymorphism.py
Last active April 2, 2024 11:23
polymorphism.py
class Person:
def __init__(self, name):
self.name = name
def introduceSelf(self):
print(f"My name is {self.name}")
class Professor(Person):
@matt-berseth
matt-berseth / encapsulation.py
Last active April 2, 2024 11:26
encapsulation.py
class Person:
def __init__(self, name):
self.name = name
def introduceSelf(self):
print(f"My name is {self.name}")
class Professor(Person):
@matt-berseth
matt-berseth / classes_and_objects.py
Last active April 2, 2024 11:25
classes_and_objects.py
class Professor:
def __init__(self, name, teaches):
self.name = name
self.teaches = teaches
def grade(self, paper):
# TODO: add logic that grades the paper
pass
@matt-berseth
matt-berseth / list_comprehensions.py
Created February 29, 2024 09:11
list_comprehensions.py
# Exercise #1
# Create a list of lengths of strings that are less than 5 characters long from a given list of strings.
words = ["hello", "world", "list", "python", "code"]
# Exercise #2
# Create a list of squares of non-negative numbers from a given list of integers.
numbers = [-2, -1, 0, 1, 2, 3, 4, 5]
@matt-berseth
matt-berseth / file_iterator.py
Created February 24, 2024 13:54
file_iterator.py
# open a large file and count the words
all_text = open("large_file.txt").read()
# at this point - all of the text in the file is read into memory.
# what happens if the text file is larger than what can fit into
# the computers memory?
all_words = all_text.split()
number_words = len(all_words)
print(f"Total number of words (read): {number_words}")
@matt-berseth
matt-berseth / search_for_fruit.py
Created February 21, 2024 11:38
search_for_fruit.py
# List of fruits
fruits = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"]
# Prompt the user to enter a fruit name
user_fruit = input("Enter the name of a fruit to search for: ").lower()
# search variant #1 - use a 'while' loop to iterate over the elements in the
# list to run the search. Stop the loop body if the fruit is found. Use the
# 'else' block to communicate to the user if the fruit was not found.
@matt-berseth
matt-berseth / if_statements.py
Created February 15, 2024 08:27
if_statements.py
## Basic if statements
if True:
print("inside block")
print("we can run multiple statements")
x = False
if x:
print("this code block will never execute")