diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..e8a5946 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,34 @@ # 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 calculator(): + # Ask for the operation + operation = input("What do you want to do?(add, sub, mult, div)\n") + + # Ask for the numbers + num1 = int(input("Num 1?\n")) + num2 = int(input("Num 2?\n")) + + # Perform the calculation + if operation == 'add': + result = num1 + num2 + elif operation == 'sub': + result = num1 - num2 + elif operation == 'mult': + result = num1 * num2 + elif operation == 'div': + if num2 != 0: + result = num1 / num2 + else: + print("Error: Division by zero is not allowed.") + return + else: + print("Error: Invalid operation.") + return + + # Print the result + print("Your result is " + str(result)) + +calculator() diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..9ba91c5 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,13 @@ # 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): + reverse_string = '' + for i in range(len(string)-1, -1, -1): + reverse_string += string[i] + return reverse_string + +print(reverse('Supacalafircationstions')) + +print("hello world") \ No newline at end of file diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..88df952 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,24 @@ print("Welcome to Chase bank.") print("Have a nice day!") +def prompt(account): + balance = 500 + account = input("Do you want to see your balance, withdraw or deposit?") + + if account == 'balance': + print('Your balance is', balance) + elif account == 'withdraw': + withdraw = int(input("How much would you like to withdraw?")) + if withdraw <= balance: + balance -= withdraw + else: + print("Insufficient balance.") + elif account == 'deposit': + deposit = int(input("How much would you like to deposit?")) + balance += deposit + + return balance + +print(prompt("Egor")) + + diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..a12e965 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,10 @@ # 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): + sorted_string = ''.join(sorted(string)) + return sorted_string + +input_string = input("Give me a string to alphabetize\n") +print('Alphabetized:', alphabetize(input_string)) \ No newline at end of file