diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..69f3c4d 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,30 @@ # 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 math(operator, num1, num2): + # if adding + if (operator == "add"): + return num1 + num2 + # else if subtracting + elif (operator == "subtract"): + return num1 - num2 + # else if multiplying + elif (operator == "multiply"): + return num1 * num2 + # num 1 * num 2 + # else + elif (operator == "divide"): + return num1 / num2 + # num 1 / num 2 + else: + return "try again" + + +# print(math("divide", 4, 5)) +operator = input("What calculation would you like to do?") +num1 = input("What is number 1?") +num2 = input("What is number 2?") +print(math(operator, int(num1), int(num2))) +# math("divide", 8, 2) \ No newline at end of file diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..2bb9955 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,10 @@ # 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): + reversed = "" + for i in (string): + reversed = i + reversed + return reversed +print(reverse("my_name_is_myles")) diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..cc7bc26 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,14 @@ print("Welcome to Chase bank.") print("Have a nice day!") +balance = input("Your current balance is\n") +process = input("What would you like to do?\n") + +if process == "deposit": + question = input("How much would you like to deposit?\n") + balance = int(balance) + int(question) +elif process == "withdraw": + question = input("How much would you like to withdraw? \n") + balance = int(balance) - int(question) + +print(f"Your current balance is {balance}") \ No newline at end of file diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..8a5994f 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,13 @@ # 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 alphabetize(string): + alpha_list = sorted(string) + alpha_string = '' + for i in alpha_list: + alpha_string = f"{alpha_string}{i}" + return alpha_string + + +print(alphabetize("alphabet")) \ No newline at end of file