From dd39eeadbabe40cf5b2e8bce6a5ac82dd84630e7 Mon Sep 17 00:00:00 2001 From: joshdoyle94 Date: Wed, 30 Nov 2022 14:33:42 -0500 Subject: [PATCH] finished responses to challenges --- challenges/01-calc.py | 17 ++++++++++++++ challenges/02-reverse.py | 10 +++++++++ challenges/03-bank.py | 42 +++++++++++++++++++++++++++++++++-- challenges/04-alphabetical.py | 9 ++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..2f9af44 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,20 @@ # 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. + +def simple_calc(): + user_choice = input("what would you like to do? Type '+', '-', '*', or '/': ") + num1 = int(input('what is number 1? ')) + num2 = int(input('what is number 2? ')) + if (user_choice == '+'): + print(num1 + num2) + elif (user_choice == '-'): + print(num1 - num2) + elif (user_choice == '*'): + print(num1 * num2) + elif (user_choice == '/'): + print(num1 / num2) + else: + return 'no valid option entered' + +simple_calc() \ No newline at end of file diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..48f81dd 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 + +def reverse_string(word): + word_reversed = '' + for character in word: + word_reversed = character + word_reversed + + print("Here is your original word: ", word) + print("Here is the reversed word: ", word_reversed) + +reverse_string(input('What word would you like to reverse today? ')) \ No newline at end of file diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..d08e46e 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,41 @@ -print("Welcome to Chase bank.") -print("Have a nice day!") +balance = int(input('Enter your starting balance: \n')) + +print("Welcome to PNC Bank!") + +def going_to_bank(): + services = input('How may we help you today? (Deposit, Withdraw, Check Balance) \n') + if (services == 'Deposit' or services == 'deposit'): + deposit_amount = int(input('How much would you like to deposit today? \n')) + print(f"You have deposited ${deposit_amount}. Your new balance is ${deposit_amount+balance}") + anything_else = input("Is there anything else you would like to do today? (Yes or No) \n") + if (anything_else == 'Yes' or anything_else == 'yes'): + going_to_bank() + elif (anything_else == 'No' or anything_else == 'no'): + print('Have a great day!') + else: + print("Hmm, I didn't understand that. Goodbye!") + elif (services == 'Withdraw' or services == 'withdraw'): + withdraw_amount = int(input('How much would you like to withdraw today? ')) + print(f"You have withdrawn ${withdraw_amount}. You have ${balance-withdraw_amount} left in your account.") + anything_else = input("Is there anything else you would like to do today? (Yes or No) \n") + if (anything_else == 'Yes' or anything_else == 'yes'): + going_to_bank() + elif (anything_else == 'No' or anything_else == 'no'): + print('Have a great day!') + else: + print("Hmm, I didn't understand that. Goodbye!") + elif (services == 'Check Balance' or services == 'check balance'): + print(f"You have ${balance} in your account") + anything_else = input("Is there anything else you would like to do today? (Yes or No) \n") + if (anything_else == 'Yes' or anything_else == 'yes'): + going_to_bank() + elif (anything_else == 'No' or anything_else == 'no'): + print('Have a great day!') + else: + print("Hmm, I didn't understand that. Goodbye!") + else: + print("Sorry, I didn't catch that.") + going_to_bank() + +going_to_bank() \ No newline at end of file diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..267fb4f 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,12 @@ # 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. + +def alphabetical(): + word = input("\n Give me a string to alphabetize: \n") + character_array = list(word) + character_array.sort() + sorted_word = "".join(character_array) + print("\n Here is your word alphabetized: \n", sorted_word) + +alphabetical() \ No newline at end of file