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
19 changes: 19 additions & 0 deletions challenges/01-calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,22 @@
# 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.

math = input("What calculation would you like to do? (add, sub, mult, div)")

num_one = input("What is the first number?")

num_two = input("What is the second number?")

def do_math(number_one, number_two):
if "add" in math:
return number_one + number_two
elif "sub" in math:
return number_one - number_two
elif "mult" in math:
return number_one * number_two
elif "div" in math:
return number_one / number_two

# Output
print(do_math(int(num_one), int(num_two)))
19 changes: 19 additions & 0 deletions challenges/02-reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@
# 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

word = input("Enter a word to reverse: ")

def reverse_word(word):
drow = ""
for letter in reversed(word):
drow += letter
print(drow)
print("".join(reversed(word)))

reverse_word(word)

# python slice syntax (works on lists or strings)
my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# [slice start (default 0): slice end (default end of list): step (default 1)]
my_list_copy = my_list[::] # make a copy with defaults
print(my_list[::-1])

print(word[::-1])
34 changes: 33 additions & 1 deletion challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
print("Welcome to Chase bank.")
print("Have a nice day!")
balance = 120000


def accounting(action, balance):
if "deposit" in action:
deposit = input("How much would you like to deposit?\n")
balance += int(deposit)
print(f"Your new balance is {balance}")
done = input("Are you done?\n")
sign_out(done, balance)
elif "withdraw" in action:
withdrawl = input("How much would you like to withdrawl?\n")
balance -= int(withdrawl)
print(f"Your new balance is {balance}")
done = input("Are you done?\n")
sign_out(done, balance)
elif "check_balance" in action:
print(f"Your balance is {balance}")
done = input("Are you done?\n")
sign_out(done, balance)

def sign_out(decision, balance):
if "yes" in decision:
pass
if "no" in decision:
action = input("What would you like to do? (deposit, withdraw, check_balance)\n")
accounting(action, balance)


print(f"Your balance is {balance}");
action = input("What would you like to do? (deposit, withdraw, check_balance)\n")
accounting(action, balance)

print("Have a nice day!")
14 changes: 14 additions & 0 deletions challenges/04-alphabetical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 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.

word = input("Enter a word to alphabetize.")
# sorted function approach
alpha = ""
for letters in sorted(word):
alpha += letters

print(alpha)

# convert to list approach
word_list = list(word)
word_list.sort()
string = "".join(word_list)
print(string)