From 300e3ae9a3073282aa626b4ae8e668c0633203e6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 12 May 2023 13:04:17 -0400 Subject: [PATCH] Complete deliverable --- challenges/01-calc.py | 18 ++++++++++++++++++ challenges/02-reverse.py | 9 +++++++++ challenges/03-bank.py | 15 +++++++++++++++ challenges/04-alphabetical.py | 6 ++++++ 4 files changed, 48 insertions(+) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..515e175 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,21 @@ # 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. + +while True: + + operation = input("What operation would you like to do? Input add, sub, mult, or div: ") + + num1 = int(input("What's your first number? ")) + + num2 = int(input("What's your second number? ")) + + if operation == "add": + print("Your result is " + str(num1 + num2)) + elif operation == "sub": + print("Your result is " + str(num1 - num2)) + elif operation == "mult": + print("Your result is " + str(num1 * num2)) + elif operation == "div": + print("Your result is " + str(num1 / num2)) + \ No newline at end of file diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..2d14240 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,12 @@ # 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(): + string = input("Enter a string: ") + reverse = "" + for letter in reversed(string): + reverse += letter + print(reverse) + +reverse_string() \ No newline at end of file diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..65e12ed 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,18 @@ print("Welcome to Chase bank.") print("Have a nice day!") +balance = input("Your current balance is\n") +balance = int(balance) +action = input("What would you like to do? (deposit, withdraw, check_balance)\n") +if action == "deposit": + deposit_amount = input("How much would you like to deposit?\n") + deposit_amount = int(deposit_amount) + new_balance = balance + deposit_amount + print("Your current balance is " + str(new_balance)) +elif action == "withdraw": + withdraw_amount = input("How much would you like to withdraw?\n") + withdraw_amount = int(withdraw_amount) + new_balance = balance - withdraw_amount + print("Your current balance is " + str(new_balance)) +elif action == "check_balance": + print("Your current balance is " + str(balance)) \ No newline at end of file diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..4e58d0b 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 = "teststring" +string_list = list(string) +string_list.sort() +string = "".join(string_list) +print(string) \ No newline at end of file