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
69 changes: 69 additions & 0 deletions challenges/01-calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,72 @@
# 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.
# user_input = input("Please enter a number: ")
# if user_input.isdigit():
# number = int(user_input)
# else:
# print("That was not a valid number.")
# exit()
# result = number + 5
# print("The result is:", result)

# value= input('the user will see this is the terminal')
is_running = True

while is_running:
# display math choices and ask user to choose 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 user to input two numbers, one by
print("Excellent math choice! Enter the first number")
number_one = input(prompt)
print("Now, enter a second number")
number_two = input(prompt)

# print(number_one, number_two)
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:
# # default for switch case
# print(f"I lied, {math_choice} isn't a math choice 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"{math_choice} makes no sense to me!")
except ValueError as e :
# handle error instead of crashing
print("That wasn't a real number 😿")

# ask user if they would like to exit
print("would you like to countinue doing 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 = "banana"
reversed_string = string[::-1]
print (reversed_string)

string="cucumber"
print("".join(reversed(string)))

string= "hello world"
reversed_string = ""
for char in string:
reversed_string = char + reversed_string
print(reversed_string)
42 changes: 42 additions & 0 deletions challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
print("Welcome to Chase bank.")
print("Have a nice day!")
balance = 4000
def welcome(name):
print("Welcome to Chase bank.")
def withdraw():
pass
def deposit():
amount = (input("How much would you like to deposit?"))
global balance
balance += amount

def check_balance(balance):
print('Your current balance is', balance)


def withdraw():
amount = float(input("How much would you like to withdraw?\n"))
global balance
if amount <= balance:
balance -= amount
else:
print("You are broke")

print ("Your current balance is")
print(balance)

while True:
action = input("What would you like to do? (deposit, withdraw, check_balance)\n")

if action == "deposit":
deposit()
check_balance()
elif action == "withdraw":
withdraw()
check_balance()
elif action == "check_balance":
check_balance()
else:
print("Invalid action.")

done = input("Are you done?\n")
if done == "yes":
print("Thank you!")
print("Have a nice day!")
18 changes: 18 additions & 0 deletions challenges/04-alphabetical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# 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 list approach
# string = "supercalifragilisticexpialidocious"
# string_list = list(string)
# string_list.sort()
# string = "".join(string_list)
# print(string)


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

# python slice syntax (works on lists or strings)
my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# [slice start (default 0): slice end (default end of list): step (default 1)]
my_list_copy = my_list[::] # make a copy with defaults
print(my_list[::-1])
print("hello"[::-1])