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

# define the function that performs the operation
def calculator(op, num1, num2):
if op == "add":
return num1 + num2
elif op == "sub":
return num1 - num2
elif op == "mult":
return num1 * num2
elif op == "div":
return num1 / num2

# get user input for the operation and the numbers
op = input("What calculation would you like to do? (add, sub, mult, div) ")
num1 = float(input("What is number 1? "))
num2 = float(input("What is number 2? "))

# call the function with the user input and display the result
result = calculator(op, num1, num2)
print("Your result is", result)

4 changes: 4 additions & 0 deletions challenges/02-reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
# 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

question = 'What is your string? '
answer = input(question)
print(answer[::-1])
30 changes: 30 additions & 0 deletions challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
print("Welcome to Chase bank.")
# Collect the user's starting balance
balance = 4000

# Display the user's current balance
print("Your current balance is")
print(balance)

# Ask the user what they want to do
action = input("What would you like to do? (deposit, withdraw, check_balance)\n")

# Perform the selected action
if action == "deposit":
amount = float(input("How much would you like to deposit?\n"))
balance += amount
elif action == "withdraw":
amount = float(input("How much would you like to withdraw?\n"))
balance -= amount
elif action == "check_balance":
pass # Do nothing
else:
print("Invalid action. Please try again.")

# Display the user's updated balance
print("Your current balance is")
print(balance)

# Ask the user if they're done
done = input("Are you done?\n")

# Say goodbye
print("Have a nice day!")

5 changes: 5 additions & 0 deletions challenges/04-alphabetical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 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.

prompt = "hello user, what's your name?"
answer = input(prompt)
alphabetized_name = ''.join(sorted(answer))
print(alphabetized_name)