From 3423b22cddd6ba6d917c9416f9ec858a5fc00b0b Mon Sep 17 00:00:00 2001 From: brogers-97 Date: Fri, 12 May 2023 10:12:29 -0700 Subject: [PATCH] finished deliverable --- challenges/01-calc.py | 40 +++++++++++++++++++++++++++++++++++ challenges/02-reverse.py | 4 ++++ challenges/03-bank.py | 21 ++++++++++++++++++ challenges/04-alphabetical.py | 6 ++++++ 4 files changed, 71 insertions(+) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..7343863 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,43 @@ # 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: + prompt = '>' + print('hello user') + print('tell me what kind of math you want to do') + print('Possible choices: add, sub, mul, div') + math_choice = input(prompt) + print(f'math choice: {math_choice}') + 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: + number_one = int(number_one) + number_two = int(number_two) + except ValueError as e: + print('that wasnt a real number') + + 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: + print(f'i lied, {math_choice} isnt a math I know about') + + print('would you like to continue? Y/n') + should_quit = input(prompt) + if should_quit == 'n': + is_running = False \ No newline at end of file diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..3e20fd9 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,7 @@ # 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 = 'hello' +print(''.join(reversed(string))) + diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..108d3e8 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,24 @@ print("Welcome to Chase bank.") print("Have a nice day!") +balance = 4000 + +def banking(): + print("Welcome to Chase bank.") + + global balance + + transaction = input("What would you like to do? (deposit, withdraw, balance)\n") + + if transaction == 'deposit': + deposit_amount = float(input("How much would you like to deposit?\n")) + balance += deposit_amount + return f"Your new balance is {balance}." + elif transaction == 'withdraw': + withdraw_amount = float(input("How much would you like to withdraw?\n")) + balance -= withdraw_amount + return f"Your new balance is {balance}." + elif transaction == 'balance': + return f"Your current balance is {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..1ba43b2 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,9 @@ # 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 = 'supercalifragilisticexpialidocious' +string_list = list(string) +string_list.sort() +string = "".join(string_list) +print(string) \ No newline at end of file