Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions challenges/01-calc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
# Use the `input()` function to prompt a user to enter something.
# 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.
is_running = True
while is_running:
# display math choices and ask user to choose one
prompt = ">"
print("Hello friend!")
print('Tell me what kind of math you would like to do.')
print('Possible choices: add, subtract, multiply, and divide.')
math_choice = input(prompt)
print(f"Math choice: {math_choice}")

# ask the user to input two numbers
print('Excellent math choice! Enter the first number to use:')
number_one = input(prompt)
print('Now enter a second number:')
number_two = input(prompt)

# convert input to integers
try:
number_one = int(number_one)
number_two = int(number_two)

# perform the selected math operation
if math_choice == 'add':
print(f"{number_one} + {number_two} = {number_one + number_two}")
elif math_choice == 'subtract':
print(f"{number_one} - {number_two} = {number_one - number_two}")
elif math_choice == 'multiply':
print(f"{number_one} * {number_two} = {number_one * number_two}")
elif math_choice == 'divide':
if number_two == 0:
print("Error: Cannot divide by zero!")
else:
print(f"{number_one} / {number_two} = {number_one / number_two}")
else:
print(f"I'm sorry, '{math_choice}' isn't a valid math operation.")

except ValueError:
print('That wasn\'t a valid number!')

# ask user if they would like to continue
print('Would you like to continue doing more math problems? (y/n)')
should_quit = input(prompt)
if should_quit.lower() == 'n':
is_running = False
11 changes: 11 additions & 0 deletions challenges/02-reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
# 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 = 'Forward'
reverse_string = ''

def reverse(string):
global reverse_string
for i in string:
reverse_string = i + reverse_string
return reverse_string

print(reverse(string))
35 changes: 34 additions & 1 deletion challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
print("Welcome to Chase bank.")
print("Have a nice day!")

balance = 4000


def bank_action():
global balance
user_choice = input('What would you like to do? (deposit, withdraw, check_balance): \n')
# global user_choice
if user_choice == 'deposit':
deposit = int(input('Please enter the amount you\'d like to deposit: \n'))
balance += deposit
print(f'Your balance after depositing is {balance}')
# continue_banking()
return balance
elif user_choice == 'withdraw':
withdraw = int(input('Please enter the amount you\'d like to withdraw: \n'))
balance -= withdraw
print(f'Your balance after withdrawing is {balance}')
# continue_banking()
return balance
elif user_choice == 'check_balance':
print(f'Your current balance is {balance}')
# continue_banking()
else:
print('Please select to deposit, withdraw, or check_balance')
bank_action()

bank_action()

continue_banking = input('Can we assist you with anything else? (yes/no): \n')
if continue_banking == 'no':
print('Have a great day!')
elif continue_banking == 'yes':
bank_action()

7 changes: 7 additions & 0 deletions challenges/04-alphabetical.py
Original file line number Diff line number Diff line change
@@ -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.


string = input('Please enter a string to sort in alphabetical order!: \n')
print(string)
alphabetic = sorted(string.lower())
str = ''
print(str .join(alphabetic))