diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9ee86e7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..4ab3a6f 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,28 @@ # 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. + + +calculation = input("What calculation would you like to do? (add, sub, mult, div): ") + +number1 = float(input("What is number 1? ")) +number2 = float(input("What is number 2? ")) + +result = None + +if calculation == "add": + result = number1 + number2 +elif calculation == "sub": + result = number1 - number2 +elif calculation == "mult": + result = number1 * number2 +elif calculation == "div": + if number2 != 0: + result = number1 / number2 + else: + print("Error: Cannot divide by zero.") +else: + print("Invalid calculation method.") + +if result is not None: + print("Your result is", result) diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..9a7cbb5 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,11 @@ # 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 = input("Enter a string: ") +reversed_string = "" + +for char in string: + reversed_string = char + reversed_string + +print(reversed_string) diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..76b6a45 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,46 @@ print("Welcome to Chase bank.") -print("Have a nice day!") + +balance = 4000 + +def check_balance(): + print("Your current balance is") + print(balance) + +def deposit(): + amount = float(input("How much would you like to deposit?\n")) + global balance + balance += amount + +def withdraw(): + amount = float(input("How much would you like to withdraw?\n")) + global balance + if amount <= balance: + balance -= amount + else: + print("You are broke") + +print ("Your current balance is") +print(balance) + +while True: + action = input("What would you like to do? (deposit, withdraw, check_balance)\n") + + if action == "deposit": + deposit() + check_balance() + elif action == "withdraw": + withdraw() + check_balance() + elif action == "check_balance": + check_balance() + else: + print("Invalid action.") + + done = input("Are you done?\n") + if done == "yes": + print("Thank you!") + 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..6c80e3e 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 alphabetize_string(string): + alphabetized_string = ''.join(sorted(string)) + return alphabetized_string + +input_string = input("Give me a string to alphabetize:\n") +result = alphabetize_string(input_string) +print("Alphabetized:", result)