From 53b97ceb98ec7b2a2605fbe7967d5b1b9b6f9906 Mon Sep 17 00:00:00 2001 From: andrewbantly Date: Thu, 11 May 2023 19:10:09 -0700 Subject: [PATCH 1/2] deliverable complete --- challenges/01-calc.py | 19 +++++++++++++++++++ challenges/02-reverse.py | 10 ++++++++++ challenges/03-bank.py | 34 +++++++++++++++++++++++++++++++++- challenges/04-alphabetical.py | 8 ++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) 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..c0d0960 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,13 @@ # 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) + +reverse_word(word) \ 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..a954162 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,11 @@ # 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.") + +alpha = "" +for letters in sorted(word): + alpha += letters + +print(alpha) From f347f50b3a500d3f5c3585ffb701c8eb1feadd2e Mon Sep 17 00:00:00 2001 From: andrewbantly Date: Fri, 12 May 2023 10:13:04 -0700 Subject: [PATCH 2/2] deliverable review --- challenges/02-reverse.py | 11 ++++++++++- challenges/04-alphabetical.py | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index c0d0960..6e02518 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -14,5 +14,14 @@ def reverse_word(word): for letter in reversed(word): drow += letter print(drow) + print("".join(reversed(word))) -reverse_word(word) \ No newline at end of file +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/04-alphabetical.py b/challenges/04-alphabetical.py index a954162..90e675a 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -3,9 +3,15 @@ # 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