diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..4a54b21 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,22 @@ # 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. + +math = input("What calculation would you like to do? (add, sub, mult, div)") + +num_one = input("What is the first number?") + +num_two = input("What is the second number?") + +def do_math(number_one, number_two): + if "add" in math: + return number_one + number_two + elif "sub" in math: + return number_one - number_two + elif "mult" in math: + return number_one * number_two + elif "div" in math: + return number_one / number_two + +# Output +print(do_math(int(num_one), int(num_two))) \ No newline at end of file diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..6e02518 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,22 @@ # 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 + +word = input("Enter a word to reverse: ") + +def reverse_word(word): + drow = "" + for letter in reversed(word): + drow += letter + print(drow) + print("".join(reversed(word))) + +reverse_word(word) + +# 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(word[::-1]) \ No newline at end of file diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..a40ade7 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,35 @@ print("Welcome to Chase bank.") -print("Have a nice day!") +balance = 120000 + +def accounting(action, balance): + if "deposit" in action: + deposit = input("How much would you like to deposit?\n") + balance += int(deposit) + print(f"Your new balance is {balance}") + done = input("Are you done?\n") + sign_out(done, balance) + elif "withdraw" in action: + withdrawl = input("How much would you like to withdrawl?\n") + balance -= int(withdrawl) + print(f"Your new balance is {balance}") + done = input("Are you done?\n") + sign_out(done, balance) + elif "check_balance" in action: + print(f"Your balance is {balance}") + done = input("Are you done?\n") + sign_out(done, balance) + +def sign_out(decision, balance): + if "yes" in decision: + pass + if "no" in decision: + action = input("What would you like to do? (deposit, withdraw, check_balance)\n") + accounting(action, balance) + + +print(f"Your balance is {balance}"); +action = input("What would you like to do? (deposit, withdraw, check_balance)\n") +accounting(action, balance) + +print("Have a nice day!") \ No newline at end of file diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..90e675a 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,17 @@ # 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. + +word = input("Enter a word to alphabetize.") +# sorted function approach +alpha = "" +for letters in sorted(word): + alpha += letters + +print(alpha) + +# convert to list approach +word_list = list(word) +word_list.sort() +string = "".join(word_list) +print(string) \ No newline at end of file