This file contains hidden or 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
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() |
This file contains hidden or 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
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") |
This file contains hidden or 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
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 |
This file contains hidden or 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
class Person: | |
def __init__(self, name): | |
self.name = name | |
def introduceSelf(self): | |
print(f"My name is {self.name}") | |
class Professor(Person): |
This file contains hidden or 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
class Person: | |
def __init__(self, name): | |
self.name = name | |
def introduceSelf(self): | |
print(f"My name is {self.name}") | |
class Professor(Person): |
This file contains hidden or 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
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 |
This file contains hidden or 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
# 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] | |
This file contains hidden or 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
# 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}") |
This file contains hidden or 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
# 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. |
This file contains hidden or 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
## 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") | |
NewerOlder