Question: Problem 1 For this exercise you will write three functions The first function called calculate _ interest will calculate the interest and return it .

Problem 1
For this exercise you will write three functions
The first function called calculate_interest will calculate the interest and return it.
The second function is called make_withdrawal will perform withdrawal and return the new balance if the withdrawal is successful, otherwise -1.
The third function is called make_deposit will perform diposit and return the new balance if the deposit is successful, otherwise -1.
Interest formula:
interest =(principal * rate * time)/100.0
"""
# !! DON'T CHANGE THE TEMPLATES BELOW. WRITE THE SOLUTIONS FOR THE GIVEN FUNCTIONS !!
# Initialize a global constant Rate
RATE =4.5
# Function to calculate new interest
def calculate_interest(principal, time):
# Write your logic for this function here.
interest =(principal * RATE * time)/100.0
return interest
# Function to calculate new balance after a withdrawal
def make_withdrawal(balance, amount):
# Write your logic for this function here.
if amount <= balance:
balance -= amount
return balance
else:
return -1
# Function to calculte new balance after a deposite
def make_deposit(balance, amount):
# Write your logic for this function here.
if amount >0:
balance += amount
return balance
else:
return -1
Problem 2
Describe your program here.
Write a function that take three inputs num1, num2, and op and performs arithmetic operations such as addition(+), subtraction(-), multiplication(*), and division(/). Your program must return the operation results based on the operator specified by the op variable.
Input:
perform_arithmetic_operations(8,9,+)
Output:
17.
Input:
perform_arithmetic_operations(-8,3,*)
Output:
-24.
Input:
perform_arithmetic_operations(b,9,+)
Output:
Invalid input!.
Input:
perform_arithmetic_operations(4,9, ~)
Output:
Unknown operator!
Input:
perform_arithmetic_operations(4,0,/)
Output:
Impossible operation!
Variables: num1, num2, op
"""
# Write the function here
def perform_arithmetic_operations(num1, num2, op):
# Write your function body here.
try:
num1= float(num1)
num2= float(num2)
except ValueError:
return "Invalid input!"
# Perform the operation based on the operator
if op =='+':
return num1+ num2
elif op =='-':
return num1- num2
elif op =='*':
return num1* num2
elif op =='/':
if num2==0:
return "Impossible operation!"
return num1/ num2
else:
return "Unknown operator!"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!