From 1c9b179d0c25edd0313432cc40f5afb900e39695 Mon Sep 17 00:00:00 2001 From: Powwow84 Date: Thu, 11 May 2023 21:22:51 -0700 Subject: [PATCH] Python challenges hw --- challenges/01-calc.py | 22 ++++++++++++++++++++++ challenges/02-reverse.py | 9 +++++++++ challenges/03-bank.py | 20 ++++++++++++++++++++ challenges/04-alphabetical.py | 8 ++++++++ 4 files changed, 59 insertions(+) diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..bee5611 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,25 @@ # 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. + + +user_input = input("what method wouls you like to use: +, -, *, / ") +user_input_num_1 = input("give me a number") +user_input_num_2 = input('give me another number') +number1 = int(user_input_num_1) +number2 = int(user_input_num_2) + +def do_math(): + if user_input == "+": + return number1 + number2 + elif user_input == "-": + return number1 - number2 + elif user_input == "*": + return number1 * number2 + elif user_input == "/": + return number1 / number2 + else: + return "not a valid operator" + +print(do_math()) + diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..489fdae 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): + reversed_string = '' + for _ in string: + reversed_string = _ + reversed_string + return reversed_string + +print(reverse_string("carebears")) diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..d694618 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,23 @@ print("Welcome to Chase bank.") print("Have a nice day!") + +action = input("Chose an action: balance, withdraw, deposit\n" ) +user_balance = 4000 + +if action == 'balance': + print(user_balance) +elif action == "withdraw": + deposit = input("how much would you like to withdraw \n") + deposit_value = int(deposit) + print(user_balance - deposit_value) +elif action == 'deposit': + withdraw = input("how much would you like to deposit \n") + withdraw_amount = int(withdraw) + print(user_balance + withdraw_amount) +else: + print("invalid option") + + + + diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..a69a046 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. + +def sort_string(string): + sorted_string = ''.join(sorted(string)) + return sorted_string + +user_string = input("Give me a string\n") + +print(sort_string(user_string))