Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python challenges hw #200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions challenges/01-calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,25 @@
# 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.


user_input = input("what method wouls you like to use: +, -, *, / ")
user_input_num_1 = input("give me a number")
user_input_num_2 = input('give me another number')
number1 = int(user_input_num_1)
number2 = int(user_input_num_2)

def do_math():
if user_input == "+":
return number1 + number2
elif user_input == "-":
return number1 - number2
elif user_input == "*":
return number1 * number2
elif user_input == "/":
return number1 / number2
else:
return "not a valid operator"

print(do_math())

9 changes: 9 additions & 0 deletions challenges/02-reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@
# 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(string):
reversed_string = ''
for _ in string:
reversed_string = _ + reversed_string
return reversed_string

print(reverse_string("carebears"))
20 changes: 20 additions & 0 deletions challenges/03-bank.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
print("Welcome to Chase bank.")
print("Have a nice day!")


action = input("Chose an action: balance, withdraw, deposit\n" )
user_balance = 4000

if action == 'balance':
print(user_balance)
elif action == "withdraw":
deposit = input("how much would you like to withdraw \n")
deposit_value = int(deposit)
print(user_balance - deposit_value)
elif action == 'deposit':
withdraw = input("how much would you like to deposit \n")
withdraw_amount = int(withdraw)
print(user_balance + withdraw_amount)
else:
print("invalid option")




8 changes: 8 additions & 0 deletions challenges/04-alphabetical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 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 sort_string(string):
sorted_string = ''.join(sorted(string))
return sorted_string

user_string = input("Give me a string\n")

print(sort_string(user_string))