gpt4 book ai didi

python - atm 取款时出现错误消息,输入金额大于或小于帐户余额时无法正常运行

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:22 26 4
gpt4 key购买 nike

我对 Python 和编码还很陌生。我正在尝试创建一个 ATM 类型的程序,让您可以存款和取款。我输入了我收到的错误消息。老实说,我只是不知道从这里该去哪里。

此外,如何通过 % 调用确保提款金额可以被 10 整除?

感谢任何帮助!

File "/Users/jess/PycharmProjects/assignment2/assignment 1.py", line 54, in <module>
r = input("Are you sure you want to deposit ", deposit, "? [Y/N]")
TypeError: [raw_]input expected at most 1 arguments, got 3

代码:

#display welcome message
print("Welcome to a Virtual Credit Union ATM!")


counter = 0
while counter < 3:
pin = input("Please input your 4-digit PIN: ")

if pin == 9876:
print("Correct PIN, will continue to menu")
break

print("Incorrect PIN, please try again")
counter += 1

if counter == 3:
print("You're locked out, Goodbye")
else:
print("Onto Menu options")


def menu(): ## Your menu design here
print "1. View Account Balance"
print "2. Withdraw cash"
print "3. Make a deposit"
print "4. Exit"


loop = True

while loop: ## While loop which will keep going until loop =False
menu() ## Displays menu
choice = input("Enter your choice [1-4]: ")

if choice == 1:
account_balance = (int, 'Your account balance is: $500')
print(account_balance)

elif choice == 2:
print "Withdraw Cash, must be multiple of 10"
withdraw = int(input('How much do you want to Withdraw?:'))

if withdraw > account_balance:
print("Insufficient funds")
withdraw = int(input("Enter new amount to Withdraw: "))

elif withdraw <= account_balance:
balance = account_balance - withdraw
print (' New Balance :', balance)

elif choice == 3:
print "Make Deposit"
deposit = int(input('How much do you want to Deposit?:'))
r = input("Are you sure you want to deposit ", deposit, "? [Y/N]")
if choice == y:
balance = account_balance + deposit
print (' New Balance:', balance)

elif choice == n:
deposit2 = input("Enter the amount you want to deposit")
balance = account_balance + deposit2
print (' New Balance:', balance)

elif choice == 4:
print "Exit, Goodbye!"
break

loop = False # This will make the while loop to end as not value of loop is set to False
else:
# Any integer inputs other than values 1-5 we print an error message
raw_input("Wrong option selection. Enter any key to try again..")

最佳答案

# comments:
# at some places you are using print function while at other you are using print as statement
# 1 == '1' false

#display welcome message
print("Welcome to a Virtual Credit Union ATM!")


counter = 0
while counter < 3:
pin = int(input("Please input your 4-digit PIN: ")) # int()

if pin == 9876:
print("Correct PIN, will continue to menu")
break
else:
print("Incorrect PIN, please try again")

counter += 1

if counter == 3:
print("You're locked out, Goodbye")
else:
print("Onto Menu options")



def menu(): ## Your menu design here
print("1. View Account Balance")
print("2. Withdraw cash")
print("3. Make a deposit")
print("4. Exit")


account_balance = 500


loop = True
while loop: ## While loop which will keep going until loop =False
menu() ## Displays menu
choice = int(input("Enter your choice [1-4]: "))

if choice == 1:
#account_balance = (int, 'Your account balance is: $500') what are you trying to do here ??

print('Your account balance is: ${}'.format(account_balance))
#print('Your account balance is: $'+str(account_balance))

elif choice == 2:
print("Withdraw Cash, must be multiple of 10")

while True:
withdraw = int(input('How much do you want to Withdraw?:'))

# 40%10 == 0 True but 42%10 == 0 False
if withdraw % 10 == 0:
if withdraw > account_balance:
print("Insufficient funds, your account balance is",account_balance)

elif withdraw <= account_balance:
#balance = account_balance - withdraw
account_balance = account_balance - withdraw #update account_balance
print (' New Balance :', account_balance)

break
else:
print("Withdraw Cash, must be multiple of 10")


elif choice == 3:
print("Make Deposit")
deposit = int(input('How much do you want to Deposit?:'))

# as pointed out in comments by PM 2 Rings and others
choice = input("Are you sure you want to deposit "+ str(deposit)+ "? [Y/N]")
if choice.lower() == 'y':
#balance = account_balance + deposit
account_balance = account_balance + deposit
print (' New Balance:', account_balance)

elif choice.lower() == 'n':

print('money not deposited')

'''
deposit2 = input("Enter the amount you want to deposit")
balance = account_balance + deposit2
print (' New Balance:', balance)
'''

elif choice == 4:
print("Exit, Goodbye!")

# no need to do both either use break or set loop to False
#break
loop = False # This will make the while loop to end as not value of loop is set to False
else:
# Any integer inputs other than values 1-5 we print an error message
dump = input("Wrong option selection. Enter any key to try again..")
<小时/>
Welcome to a Virtual Credit Union ATM!
Please input your 4-digit PIN: 9876
Correct PIN, will continue to menu
Onto Menu options
1. View Account Balance
2. Withdraw cash
3. Make a deposit
4. Exit
Enter your choice [1-4]: 1
Your account balance is: $500
1. View Account Balance
2. Withdraw cash
3. Make a deposit
4. Exit
Enter your choice [1-4]: 2
Withdraw Cash, must be multiple of 10
How much do you want to Withdraw?:77
Withdraw Cash, must be multiple of 10
How much do you want to Withdraw?:400
New Balance : 100
1. View Account Balance
2. Withdraw cash
3. Make a deposit
4. Exit
Enter your choice [1-4]: 3
Make Deposit
How much do you want to Deposit?:338
Are you sure you want to deposit 338? [Y/N]y
New Balance: 438
1. View Account Balance
2. Withdraw cash
3. Make a deposit
4. Exit
Enter your choice [1-4]: 9
Wrong option selection. Enter any key to try again..
1. View Account Balance
2. Withdraw cash
3. Make a deposit
4. Exit
Enter your choice [1-4]: 1
Your account balance is: $438
1. View Account Balance
2. Withdraw cash
3. Make a deposit
4. Exit
Enter your choice [1-4]: 4
Exit, Goodbye!

关于python - atm 取款时出现错误消息,输入金额大于或小于帐户余额时无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52462402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com