
Python Task on Savings Account and Make Change
- 9th Jun, 2022
- 15:59 PM
# Take the current balance and amount to be withdrawn as input
current_balance = float(input("Enter current balance : "))
amount_withdrawn = float(input("Enter amount of withdrawal : "))
# Check condition
if amount_withdrawn > current_balance:
print("Withdrawal denied.")
else:
# Calculate new balance
new_balance = current_balance - amount_withdrawn
print("The new balance is ${:.2f}.".format(new_balance))
# Cost of apples per pound
cost_per_pound = 2.50
# Take the number of pounds and payment as input
n_pounds = float(input("Enter weight in pounds : "))
payment = float(input("Enter payment in dollars : "))
# Calculate total cost
total_cost = n_pounds*cost_per_pound
# Check condition
if payment >= total_cost:
change = payment - total_cost
print("Your change is ${:.2f}.".format(change))
else:
owe = total_cost - payment
print("You owe ${:.2f} more.".format(owe))