Python 定义存款循环
当我运行代码时,存款循环给我一个错误,说我没有定义存款。这和文件的读写有什么关系吗?我的代码似乎正确,有人能帮忙吗?任何帮助都将不胜感激。谢谢Python 定义存款循环,python,Python,当我运行代码时,存款循环给我一个错误,说我没有定义存款。这和文件的读写有什么关系吗?我的代码似乎正确,有人能帮忙吗?任何帮助都将不胜感激。谢谢 import time import pickle print("Hello, Welcome to Shawn's Bank ATM") print("") print("Please begin with creating an account") name=input("Enter your name: ") phone=input("Enter
import time
import pickle
print("Hello, Welcome to Shawn's Bank ATM")
print("")
print("Please begin with creating an account")
name=input("Enter your name: ")
phone=input("Enter your phone number: ")
address=input("Enter your address: ")
code=input("Please enter a 4 digit pin to use as your passcode: ")
print()
print("Your account summary is:")
print("Name:" + name)
print("Phone Number:" + phone)
print("Address:" + address)
print("Pin Code:" + code)
print()
personalData = open("Personal data.txt","w")
personalData.write("Your name is " + name + "\n")
personalData.write("Your address is " + address + "\n")
personalData.write("Your phone number is " + phone + "\n")
personalData.write("Your password is " + code + "\n") #the program will write the users information to a file, which can be called up by choosing one of the options
personalData.close()
history = open("History.txt","w")
history.close() #opens all files then closes them, easier to write to them when they are already made
personalData_1 = open("Personal data Checking Account.txt","w")
personalData_1.close()
personalData_2 = open("Personal data Savings Account.txt","w")
personalData_2.close()
balance_1=float(input("Enter an amount to deposit into the savings account: "))
balance=float(input("Enter an amount to deposit into the chequing account: "))
print()
print(name,", Thank you for creating an account.")
def printMenu():
print()
print("Please choose an option below:")
print("""
Enter b to Check your Balance
Enter d to Deposit money into your Account
Enter w to Withdraw money from your Account
Enter t to transfer money from chequing to savings
Enter s to transfer money from savings to chequing
Enter h to view your transaction history
Enter q to Quit the Program """)
print("")
def getTransaction():
transaction=str(input("What would you like to do? "))
return transaction
def withdraw_1(balance_1,amount):
global balance
balance=bal-amt
if balance<0:
balance=balance-10
def formatCurrency(amt):
return "$%.2f" %amt
###MAIN PROGRAM###
printMenu()
command=str(getTransaction())
while command!="q":
if (command=="b"):
print(name,"Your current balance in your savings account is",formatCurrency(balance_1 ))
print(name,"Your current balance in your chequing account is",formatCurrency(balance))
printMenu()
command=str(getTransaction())
elif (command=="d"):
deposit=input("Press 1 for savings account//Press 2 for chequing account")
if deposit=='1':
amount=float(input("Amount to deposit into savings account? "))
balance_1=balance_1+amount
history = open("History.txt","w")
history.write(time.strftime("%c") + ": $" + (str(depositing) + " deposit into savings.\n"))
history.close()
printMenu()
command=str(getTransaction())
if deposit=='2':
amount=float(input("Amount to deposit into chequing account? "))
balance=balance+amount
history = open("History.txt","w")
history.write(time.strftime("%c") + ": $" + (str(depositing) + " deposit into chequing.\n"))
history.close()
printMenu()
command=str(getTransaction())
elif (command=="w"):
withdraw=input("Press 1 for savings account//Press 2 for chequing account")
if withdraw=='1':
amount=float(input("Amount to withdraw from savings account? "))
withdraw_1(balance_1,amount)
history = open("History.txt","w")
history.write(time.strftime("%c") + ": $" + (str(amount) + " withdrawal from savings.\n"))
history.close()
if withdraw=='2':
amount=float(input("Amount to withdraw from chequing account? "))
withdraw_1(balance,amount)
history = open("History.txt","w")
history.write(time.strftime("%c") + ": $" + (str(amount) + " withdrawal from chequing.\n"))
history.close()
printMenu()
command=str(getTransaction())
elif (command=="h"):
history = open("History.txt","r")
print(history.read())
history.close()
elif (command=="t"):
transfer = float(input("Enter the amount you would like to transfer from your chequing account to your savings account "))
balance_1 = balance - transfer
print("Your balance in your savings account now is $", balance)
print()
print("Your balance in your Chequing Account now is $", balance) #will take away money from checking account, and add to the savings account, will also write to the file aswell
personalData_2 = open("Personal data Savings Account.txt","w")
personalData_2.write("Your new balance is $" + (str(balance)))
personalData_2.close()
history = open("History.txt","w")
history.write(time.strftime("%c") + ": $" + (str(amount) + " has been transferred from chequing to savings account.\n"))
history.close()
printMenu()
command=str(getTransaction())
elif (command=="s"):
transfer_1 = float(input("Enter the amount you would like to transfer from your Savings Account to Chequing Account "))
balance_1 = balance + transfer_1
print("Your balance in your checking account now is $", balance_1)
print() #will take away money from savings account, and add to the checking account, will also write to the file aswell
print("Your balance in your Savings account now is $", balance)
personalData_1 = open("Personal data Checking Account.txt","w")
personalData_1.write("Your new balance is $" + (str(balance)))
personalData_1.close()
history = open("History.txt","w")
history.write(time.strftime("%c") + ": $" + (str(amount) + " has been transferred from savings to chequing account.\n"))
history.close()
printMenu()
command=str(getTransaction())
else:
print("Incorrect command. Please try again.")
printMenu()
command=str(getTransaction())
print(name,"Goodbye! See you again soon")
导入时间
进口泡菜
打印(“您好,欢迎使用肖恩的银行自动取款机”)
打印(“”)
打印(“请从创建帐户开始”)
name=输入(“输入您的姓名:”)
电话=输入(“输入您的电话号码:”)
地址=输入(“输入您的地址:”)
代码=输入(“请输入一个4位pin作为您的密码:”)
打印()
打印(“您的帐户摘要为:”)
打印(“名称:”+名称)
打印(“电话号码:”+电话)
打印(“地址:”+地址)
打印(“Pin码:”+码)
打印()
personalData=打开(“Personal data.txt”、“w”)
personalData.write(“您的名字是“+name+”\n”)
personalData.write(“您的地址是”+地址+“\n”)
personalData.write(“您的电话号码是“+phone+”\n”)
personalData.write(“您的密码为“+code+”\n”)#该程序将用户信息写入一个文件,可通过选择其中一个选项调用该文件
personalData.close()
历史=打开(“history.txt”、“w”)
history.close()#打开所有文件,然后关闭它们,以便在已经创建文件时更容易写入
personalData_1=打开(“Personal data Checking Account.txt”、“w”)
personalData_1.close()
personalData_2=打开(“Personal data saving Account.txt”,“w”)
personalData_2.close()
余额=浮动(输入(“输入要存入储蓄账户的金额:”)
余额=浮动(输入(“输入要存入支票账户的金额:”)
打印()
打印(名称,“,感谢您创建帐户。”)
def printMenu():
打印()
打印(“请在下面选择一个选项:”)
打印(“”)
输入b检查您的余额
输入d将钱存入您的帐户
输入w从您的帐户中提款
输入t将钱从支票转账到储蓄
输入s将资金从储蓄转移到支票
输入h以查看您的交易历史记录
输入q退出程序“”)
打印(“”)
def getTransaction():
transaction=str(输入(“您想做什么?”)
退货交易
def取款1(余额1,金额):
全球平衡
余额=余额金额
如果余额您检查余额或存款,但无论用户是否实际选择了“存款”,您都会检查存款选择是什么(储蓄还是支票)。请缩进相关块,使其仅在用户选择“存款”时出现:
您检查余额或存款,但无论用户是否实际选择了“存款”,您都会检查存款选择是什么(储蓄还是支票)。缩进相关块,使其仅在用户选择“存款”时出现:
您将存款用作整数,但在引用对象之前(在项目开始时)从未定义过该对象
您将存款用作整数,但在引用对象之前(在项目开始时)从未定义过该对象
如果对账单有误,您的存款缩进严重吗?你能告诉我如何正确地缩进它吗?谢谢您的代码中没有“存款循环”。我指的是对账单..请看您缩进取款
块的方式,这是正确的。如果对账单错误,您的存款缩进严重吗?你能告诉我如何正确地缩进它吗?谢谢您的代码中没有“存款循环”。我指的是对账单..sorry看看您缩进取款
块的方式,这是正确的。
elif (command=="d"):
deposit=input("Press 1 for savings account//Press 2 for chequing account")
if deposit=='1':
...
elif deposit=='2':
...
deposit = 0