From 6921a10d14526f564cce1c175bac6bddf80c3e76 Mon Sep 17 00:00:00 2001 From: dxk0ta Date: Fri, 12 May 2023 10:10:39 -0700 Subject: [PATCH 1/2] hw finished --- challenges/01-calc.py | 48 ++++++++++++++++++++++++++++++++--- challenges/02-reverse.py | 11 ++++++++ challenges/03-bank.py | 35 ++++++++++++++++++++++++- challenges/04-alphabetical.py | 8 ++++++ 4 files changed, 97 insertions(+), 5 deletions(-) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..3daae21 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -1,4 +1,44 @@ -# Use the `input()` function to prompt a user to enter something. -# 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 choose one + prompt = ">" + print("Hello friend!") + print('Tell me what kind of math you would like to do.') + print('Possible choices: add, subtract, multiply, and divide.') + 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) + + # convert input to integers + try: + number_one = int(number_one) + number_two = int(number_two) + + # perform the selected math operation + if math_choice == 'add': + print(f"{number_one} + {number_two} = {number_one + number_two}") + elif math_choice == 'subtract': + print(f"{number_one} - {number_two} = {number_one - number_two}") + elif math_choice == 'multiply': + print(f"{number_one} * {number_two} = {number_one * number_two}") + elif math_choice == 'divide': + if number_two == 0: + print("Error: Cannot divide by zero!") + else: + print(f"{number_one} / {number_two} = {number_one / number_two}") + else: + print(f"I'm sorry, '{math_choice}' isn't a valid math operation.") + + except ValueError: + print('That wasn\'t a valid number!') + + # ask user if they would like to continue + print('Would you like to continue doing more math problems? (y/n)') + should_quit = input(prompt) + if should_quit.lower() == 'n': + is_running = False \ No newline at end of file diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..33781ba 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,14 @@ # 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 = 'Forward' +reverse_string = '' + +def reverse(string): + global reverse_string + for i in string: + reverse_string = i + reverse_string + return reverse_string + +print(reverse(string)) \ No newline at end of file diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..d8db7cd 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,36 @@ print("Welcome to Chase bank.") -print("Have a nice day!") + +balance = 4000 + + +def bank_action(): + global balance + user_choice = input('What would you like to do? (deposit, withdraw, check_balance): \n') + # global user_choice + if user_choice == 'deposit': + deposit = int(input('Please enter the amount you\'d like to deposit: \n')) + balance += deposit + print(f'Your balance after depositing is {balance}') + # continue_banking() + return balance + elif user_choice == 'withdraw': + withdraw = int(input('Please enter the amount you\'d like to withdraw: \n')) + balance -= withdraw + print(f'Your balance after withdrawing is {balance}') + # continue_banking() + return balance + elif user_choice == 'check_balance': + print(f'Your current balance is {balance}') + # continue_banking() + else: + print('Please select to deposit, withdraw, or check_balance') + bank_action() + +bank_action() + +continue_banking = input('Can we assist you with anything else? (yes/no): \n') +if continue_banking == 'no': + print('Have a great day!') +elif continue_banking == 'yes': + bank_action() diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..4f5ad82 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. + + +string = input('Please enter a string to sort in alphabetical order!: \n') +print(string) +alphabetic = sorted(string.lower()) +# print(alphabetic) +str = '' +print(str .join(alphabetic)) \ No newline at end of file From 424bab522b3b929d89cddb2fadab7c22f0175638 Mon Sep 17 00:00:00 2001 From: dxk0ta Date: Fri, 12 May 2023 10:12:00 -0700 Subject: [PATCH 2/2] finished --- challenges/04-alphabetical.py | 1 - 1 file changed, 1 deletion(-) diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 4f5ad82..dcb6cb4 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -6,6 +6,5 @@ string = input('Please enter a string to sort in alphabetical order!: \n') print(string) alphabetic = sorted(string.lower()) -# print(alphabetic) str = '' print(str .join(alphabetic)) \ No newline at end of file