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
35 changes: 35 additions & 0 deletions challenges/01-calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,38 @@
# 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.
# Create a simple calculator that first asks the user what method they would like
# to use (addition, subtraction, multiplication, division) and then asks the user
# for two numbers, returning the result of the method with the two numbers. Here
# is a sample prompt:

# ```
# What calculation would you like to do? (add, sub, mult, div)
# add
# What is number 1?
# 3
# What is number 2?
# 6
# Your result is 9

method = input('What math do you want to do today (add, sub, mult, div)? ')
firstnum = int(input('What is your first number? '))
secondnum = int(input('What is your second number? '))

def calculator(meth, first, second):
if meth.lower() not in ('add', 'sub', 'mult', 'div'):
print('sorry, response invalid, please choose a proper method')
elif (meth == 'add'):
return first + second
elif (meth == 'sub'):
return first - second
elif (meth == 'mult'):
return first * second
else:
return first / second


print('your result is', calculator(method, firstnum, secondnum))



20 changes: 20 additions & 0 deletions challenges/02-reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@
# 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
# Reverse a string manually. Don't use s[::-1] (even though that's awesome).
# Create a new variable storing an empty string and add the letters from
# the first string one by one. The for loop should iterate over the length
# of the string and you should access letters individually.

# Below is some sample output.

# ```
# Enter a string:
# reverse_me
# em_esrever


def reverse_string(str):
rev_str = ''
for i in str:
rev_str = i + rev_str
return rev_str

print(reverse_string('hello'))
54 changes: 53 additions & 1 deletion challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
# Create a prompt that asks the user if they would like to display their balance,
# withdraw or deposit. Write three methods to perform these calculations and
# output the result to the user.

# Gather user input using the `input` function. Note that input always returns
# user input as a string. You have to manually convert it to an int or a float
# to make it behave like number. Also, end the input prompt with a \n newline
# character if you want the user to type in on the next line.

# ```
# age = input("How old are you?\n")
# age = int(age)
# ```

# Here is a sample output:

# ```
# Your current balance is
# 4000
# What would you like to do? (deposit, withdraw, check_balance)
# deposit
# How much would you like to deposit?
# 1000
# Your current balance is 5000
# Are you done?
# yes
# Thank you!


print("Welcome to Chase bank.")
print("Have a nice day!")
balance = int(input('your current balance is '))
# print('your current balance is ', balance)
action = input('Would you like to display your balance, withdraw, or deposit (please enter - balance, withdraw, deposit)? ')
# firstnum = int(input('What is your first number? '))
# secondnum = int(input('What is your second number? '))
def bank_action(action):
if action.lower() not in ('balance', 'withdraw', 'deposit'):
print('sorry, response invalid, please choose a proper action')
elif (action == 'balance'):
print('your current balance is ', balance)

elif (action == 'withdraw'):
how_much = int(input('how much would you like to withdraw? '))
print('your current balance is ', balance - how_much)

else:
how_much = int(input('how much would you like to deposit? '))
print('your current balance is ', balance + how_much)





print("Have a nice day!", bank_action(action))

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

# Create a function that takes a string and returns the string with the letters in
# alphabetical order (ie. `hello` becomes `ehllo`), Assume numbers and punctuation
# symbols will not be included in the string.

# ```
# Give me a string to alphabetize
# supercalifragilisticexpialidocious
# Alphabetized: aaacccdeefgiiiiiiillloopprrssstuux
# ```

alpha_string = ''

def alpha_it(str):

sorted_str = sorted(str)
print(sorted_str)
alpha_string = ''.join(sorted_str)

print(alpha_string)


alpha_it('supercalifragilisticexpialidocious')