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
62 changes: 62 additions & 0 deletions challenges/01-calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,65 @@
# input() always returns a string value. If you ever want someone
# to enter a number you have to use the `int()` function to convert
# what they typed in to a string.

is_running = True

while is_running:
# display math choices and ask user to chose one
prompt = ">"
print("Hello, User🙋‍♂️")
print("Tell me what kind of math you would like to do")
print("possible choices: add, sub, mul, div")
math_choice = input(prompt)
print(f"math choice: {math_choice}")


# ask the user to input two numbers
print ("Excellent math choice! Enter the first number to use")
number_one = input(prompt)
print("Now, enter a second Number")
number_two = input(prompt)

try:
# convert input to integers
number_one = int(number_one)
number_two = int(number_two)

# if/elif/else
# og dictionary switch
switch = {
"add": number_one + number_two,
"sub": number_one - number_two,
"mul": number_one * number_two,
"div": number_one / number_two
}

if math_choice in switch:
print(f"result: {switch[math_choice]}")
else:
# defualt for the switch case
print(f"I lied, {math_choice} isn't a math I know about")

# match case (new python switch)
match math_choice:
case "add":
print(f"{number_one} + {number_two} = {number_one + number_two}")
case "sub":
print(f"{number_one} - {number_two} = {number_one - number_two}")
case "mul":
print(f"{number_one} * {number_two} = {number_one * number_two}")
case "div":
print(f"{number_one} / {number_two} = {number_one / number_two}")
case _:
print(f"{number_one} makes no sense to me! ")

except ValueError as e:
# handle error instead of crashing
print("That wasn't a real number!")


# ask the user if they would like to exit
print("would you like to contine doin math with me [y/n]?")
should_quit = input(prompt)
if should_quit == "n":
is_running = False
12 changes: 12 additions & 0 deletions challenges/02-reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@
# several ways to reverse a string, and it's a good read!
#
# http://www.techbeamers.com/essential-python-tips-tricks-programmers/?utm_source=mybridge&utm_medium=blog&utm_campaign=read_more#tip1

string = "Hello"

reversed_string = reversed(string)
new_string = ""
for letter in reversed(string):
new_string =+ letter

print(new_string)


# print("".join(reversed(string)))
46 changes: 46 additions & 0 deletions challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
print("Welcome to Chase bank.")
print("Have a nice day!")

class BankAccount:
def __init__(self):
self.balance = 0

def deposit(self, amount):
self.balance += amount
return self.balance

def withdraw(self, amount):
if amount > self.balance:
print("Insufficient balance!")
return self.balance
else:
self.balance -= amount
return self.balance

def check_balance(self):
return self.balance


def main():
account = BankAccount()

while True:
print(f"Your current balance is\n{account.check_balance()}")
action = input("What would you like to do? (deposit, withdraw, check_balance)\n")

if action.lower() == "deposit":
amount = float(input("How much would you like to deposit?\n"))
account.deposit(amount)
elif action.lower() == "withdraw":
amount = float(input("How much would you like to withdraw?\n"))
account.withdraw(amount)
elif action.lower() == "check_balance":
pass
else:
print("Invalid action. Please enter 'deposit', 'withdraw' or 'check_balance'.")

done = input("Are you done? (yes/no)\n")
if done.lower() == 'yes':
print("Thank you!")
break


if __name__ == "__main__":
main()
19 changes: 19 additions & 0 deletions challenges/04-alphabetical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# You'll need to use a couple of built in functions to alphabetize a string.
# Try to avoid looking up the exact answer and look at built in functions for
# lists and strings instead.


# convert to lsit approch
string = "sjndgnsndflafdkjsngnsdffgh"
string_list = list(string)
string_list.sort()
string = "".join(string_list)
print(string)

# sorted function approach
print("".join(sorted(string)))


# python slice syntax
my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# [slice start (default 0): slice end(deflaut 0): step (defualt 1)]
my_list_copy = my_list[::] # make a copy with defaults
# print(my_list[::2]) # increments by 2's
# print(my_list[::-1]) # reverses the list