ATM SCRIPT CODIO - Trying to understand my error. Any insight would be appreciated

2.8k Views Asked by At

I am new to coding, and I am trying to understand why I am getting this error. It's some sort of spacing error, and I've been working on this for quite a while now. Any insight would be appreciated. I've also inserted my error on codio.

Actual Output:

What would you like to do?

How much would you like to withdraw today? Withdraw amount was $100.00, your current balance is $400.25

Thank you for banking with us.

Expected Output:

What would you like to do?

How much would you like to withdraw today?

Withdrawal amount was $100.00, current balance is $400.25

Actual Output:

What would you like to do?

How much would you like to withdraw today? $700.00 is greater that your account balance of $500.25

Thank you for banking with us.

Expected Output:

What would you like to do?

How much would you like to withdraw today?

$700.00 is greater than your account balance of $500.25

Codio Error

import sys

#account balance 
account_balance = float(500.25)


#<--------functions go here-------------------->
#printbalance function

def balance():
    print("Your current balance: $%.2f" % account_balance)

#deposit function

def deposit():
     deposit_amount = float(input("How much would you like to deposit? "))
     balance = account_balance - deposit_amount
     print("Deposit amount was $%.2f, current balance is $%.2f" % (deposit_amount, balance))

#withdraw function

def withdraw():
    withdraw_amount = float(input("How much would you like to withdraw today? "))
    if withdraw_amount > account_balance:
        print("$%.2f is greater that your account balance of $%.2f" % (withdraw_amount, account_balance))
    else:
        balance = account_balance - withdraw_amount
        print("Withdraw amount was $%.2f, your current balance is $%.2f" % (withdraw_amount, balance))

#User Input goes here, use if/else conditional statement to call function based on user input

userchoice = input ("What would you like to do?\n")

if (userchoice == "D"):
    deposit()
elif (userchoice == "B"):
    balance()
elif (userchoice == "W"):
    withdraw()


print("Thank you for banking with us.")
2

There are 2 best solutions below

0
On
enter code hereimport sys

account balance

account_balance = float(500.25)

<--------functions go here-------------------->

printbalance function

def balance():
    print("Your current balance : $%.2f" % account_balance)

deposit function

def deposit():
     deposit_amount = float(input("How much would you like to deposit today?\n"))
     balance = account_balance + deposit_amount
     print("Deposit was $%.2f, current balance is $%.2f" % (deposit_amount,balance))

withdraw function

def withdraw():
    withdraw_amount = float(input("How much would you like to withdraw today?\n"))
    if withdraw_amount > account_balance:
    print("$%.2f is greater than your account balance of $%.2f" % (withdraw_amount, 
    account_balance))
else:
    balance = account_balance - withdraw_amount
    print("Withdrawal amount was $%.2f, current balance is $%.2f" % (withdraw_amount, balance))

User Input goes here, use if/else conditional statement to call function based on user input

userchoice = input ("What would you like to do?\n")


if (userchoice == "D"):
    deposit()
elif (userchoice == "B"):
    balance()
elif (userchoice == "W"):
    withdraw()


print("Thank you for banking with us.")

For the first couple of checks, make sure to put a # sign in the print("Thank you for banking with us.") area, as it is not supposed to be written.

This is the final revision for this code.

1
On

I think part of the problem is that the "Thank you for banking with us." message is not supposed to be output. Also, it seems that the tests require you to print a line break after taking input (which would normally be input by the user).