From 7998362b1836ba6ee7d39d92102d6110b5e7411d Mon Sep 17 00:00:00 2001 From: MalcolmKemp Date: Fri, 3 Mar 2023 10:09:29 -0500 Subject: [PATCH 1/2] 'attempted' --- challenges/01-calc.py | 5 +++++ challenges/02-reverse.py | 4 ++++ challenges/04-alphabetical.py | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..231d291 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,8 @@ # 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. + +question = 'What is your name?' +answer = input(question) +print('Hello,', answer) + diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..8239239 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 + +question = 'What is your string? ' +answer = input(question) +print(answer[::-1]) diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..794e002 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,8 @@ # 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. + +prompt = "hello user, what's your name?" +answer = input(prompt) +alphabetized_name = ''.join(sorted(answer)) +print(alphabetized_name) From 3d8f0564d92d2a8764f70b8d40152afb2e616309 Mon Sep 17 00:00:00 2001 From: MalcolmKemp Date: Tue, 7 Mar 2023 15:48:53 -0500 Subject: [PATCH 2/2] 'completed' --- challenges/01-calc.py | 22 +++++++++++++++++++--- challenges/03-bank.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 231d291..ebfcaf2 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -3,7 +3,23 @@ # to enter a number you have to use the `int()` function to convert # what they typed in to a string. -question = 'What is your name?' -answer = input(question) -print('Hello,', answer) +# define the function that performs the operation +def calculator(op, num1, num2): + if op == "add": + return num1 + num2 + elif op == "sub": + return num1 - num2 + elif op == "mult": + return num1 * num2 + elif op == "div": + return num1 / num2 + +# get user input for the operation and the numbers +op = input("What calculation would you like to do? (add, sub, mult, div) ") +num1 = float(input("What is number 1? ")) +num2 = float(input("What is number 2? ")) + +# call the function with the user input and display the result +result = calculator(op, num1, num2) +print("Your result is", result) diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..e2566f4 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,33 @@ print("Welcome to Chase bank.") +# Collect the user's starting balance +balance = 4000 + +# Display the user's current balance +print("Your current balance is") +print(balance) + +# Ask the user what they want to do +action = input("What would you like to do? (deposit, withdraw, check_balance)\n") + +# Perform the selected action +if action == "deposit": + amount = float(input("How much would you like to deposit?\n")) + balance += amount +elif action == "withdraw": + amount = float(input("How much would you like to withdraw?\n")) + balance -= amount +elif action == "check_balance": + pass # Do nothing +else: + print("Invalid action. Please try again.") + +# Display the user's updated balance +print("Your current balance is") +print(balance) + +# Ask the user if they're done +done = input("Are you done?\n") + +# Say goodbye print("Have a nice day!")