diff --git a/challenges/01-calc.py b/challenges/01-calc.py index 87f5190..09f7027 100644 --- a/challenges/01-calc.py +++ b/challenges/01-calc.py @@ -2,3 +2,33 @@ # 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. + + + +# age = input("Please enter your age: ") +# age = int(age) +# print("In ten years, you will be", age + 10, "years old.") +# + + +# input to allow users to enter something +calc = input("Enter the a num operation you like to do: (add, sub, mult, div) ") + +num1 = int(input("The First Number: ")) +num2 = int(input("The Second Number: ")) + +if calc == "add": + result = num1 + num2 +elif calc == "sub": + result = num1 - num2 +elif calc == "mult": + result = num1 * num2 +elif calc == "div": + result = num1 / num2 +else: + print("Invalid input, please try again.") + exit() + +print("Your result is", result) + + diff --git a/challenges/02-reverse.py b/challenges/02-reverse.py index 8cf2677..02021c7 100644 --- a/challenges/02-reverse.py +++ b/challenges/02-reverse.py @@ -6,3 +6,20 @@ # 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 + + + +#prompt the user to inter something +string = input(" Enter the string to reverse") +#initiliazing empty string +reversed_string = "" + +for i in range(len(string)): + reversed_string += string[len(string)-i-1] +# The expression 'string[len(string)-i-1]' +# calculates the index of the character to be added to the +# 'reversed_string' variable. + +# The loop continues until all the characters in the input string have been added to the +# 'reversed_string' variable. +print(reversed_string) diff --git a/challenges/03-bank.py b/challenges/03-bank.py index 554cb1d..52b53d0 100644 --- a/challenges/03-bank.py +++ b/challenges/03-bank.py @@ -1,3 +1,82 @@ print("Welcome to Chase bank.") print("Have a nice day!") +balance = 4000 + +def deposit(balance, amount): + return balance + amount + +def withdraw(balance, amount): + return balance - amount + +print("Your current balance is") +print(balance) + + +# takes input from customers +transaction = input("What would you like to do? (deposit, withdraw, check_balance)\n") + +if transaction == "deposit": + + # prompts with questions in new line + amount = int(input("How much would you like to deposit?\n")) + balance = deposit(balance, amount) + print("Your current balance is", balance) +elif transaction == "withdraw": + amount = int(input("How much would you like to withdraw?\n")) + balance = withdraw(balance, amount) + print("Your current balance is", balance) +elif transaction == "check_balance": + print("Your current balance is", balance) + +done = input("Are you done?\n") + +if done == "yes": + print("Thank you!") + + + + +# from hashlib import new + + +# print("Welcome to Chase bank.") +# print("Have a nice day!") +# session = True +# account = 0 + + +# def new_operation(): +# global session +# input("something else? (yes, no) \n") +# if (new_operation == "yes"): +# session = True +# elif (new_operation == "no"): +# session = False + + +# while session == True: + +# operation = input("What would you like to do? (deposit, withdraw, check balance) \n") + +# if (operation == "deposit"): +# num1 = input("Deposit quantity \n") +# num1 = int(num1) +# account = account + num1 +# print(f"Your account is now {account}") +# new_operation() + +# elif (operation == "withdraw"): +# num2 = input("Withdraw quantity \n") +# num2 = int(num2) +# account = account - num2 +# print(f"Your account is now {account}") +# new_operation() + +# elif (operation == "check balance"): +# print(f"your balance is {account} \n") +# new_operation() +# print(session) + + +# print("Have a nice day!") \ No newline at end of file diff --git a/challenges/04-alphabetical.py b/challenges/04-alphabetical.py index 5051ec4..585e2db 100644 --- a/challenges/04-alphabetical.py +++ b/challenges/04-alphabetical.py @@ -1,3 +1,41 @@ -# 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. +# # 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 alphabetize_string(string): +# # convert string to a list of characters +# chars = list(string) +# # sort the list in alphabetical order +# chars.sort() +# # join the list of characters back into a string +# alphabetized_string = ''.join(chars) +# return alphabetized_string + +# # example usage +# user_string = input("Give me a string to alphabetize\n") +# result = alphabetize_string(user_string) +# print("Alphabetized:", result) + + + +# print('Please Enter Anything to Reverse.') +# 00 +# string = input() +# sorted_string = sorted(string) +# new_string = "".join(sorted_string) +# print(new_string) + + + +def reverse_str(): + # Ask the user to enter a string + string = input("Enter a something: ") +# slicing method + reversed_str = string[::-1] + return reversed_str + +# Example usage: +print(reverse_str()) + + + +