-2
나는 완전히 잃어버린. 우리의 숙제가 있습니다 :ATM 계정 숙제 (클래스, 텍스트 파일, 개체)
- 가 자신의 이름과 PIN을
- 프로그램을 사용자를 묻는 ATM 프로그램을 만듭니다가, 예금, 또는 종료, 잔액을 확인 철회 할 경우 사용자 요청을 통해 루프. 사용자가 종료를 선택하면 루프가 종료됩니다. 초기 잔액은 10,000 달러입니다.
- 모든 거래를 기록하는 텍스트 파일을 만듭니다. 파일의 첫 번째 두 라인은 사용자의 이름과 핀
- 해야
- 프로그램의 요구를 (, 잔액을 확인, 예금 인출) 사용자로부터 정보를 표시합니다 초기화 및 STR에게 기능을 포함라는 클래스를 생성 파일에서 읽고 객체를 만들 수 있습니다. 오브젝트의 필드는 이름, 핀 및 저울입니다. 6. 핀 번호와 그들이 제공 한 이름이 BAcc 객체의 이름과 핀 번호와 일치하지 않으면 프로그램이 종료됩니다. 그렇지 않으면 파일을 업데이트하려는만큼 많은 트랜잭션을 생성 할 수 있습니다. 7. try : blocks을 사용하여 처리해야하는 오류가 있습니다! 여기에는 잘못된 데이터 입력과 철수시 불충분 한 금액이 포함됩니다.
이것은 현재 가지고있는 코드입니다. 많은 작업을 수행하지는 않지만 연결하는 방법이 필요합니다.
accountfile=open("ATMACC.txt", "a")
name=input("What is your name? ")
pin=input("What is your Pin #? ")
accountfile.write("Name: " + name + "\n" + "PIN: " + pin + "\n")
USER_BALANCE = 10000
class BankAcc(object):
def __init__(self,name,pin,balance):
name = self.name
pin = self.pin
10000 = self.balance
def __str__(self):
return "Bank Account with Balance {}".format(self.name,self.balance)
def checkbalance(self):
print(self)
def deposit(self,amount):
self.amount += amount
def withdraw(self,amount):
if self.balance > amount:
self.balance -= amount
else:
raise ValueError
while True:
answer=input("Would you like to deposit, withdraw, check balance, or exit? ")
if answer=="deposit" or answer== "Deposit":
x= input("How much would you like to deposit? ")
USER_BALANCE += float(x)
print ("Your new balance is: $" + str(USER_BALANCE))
accountfile.write("\n" + "Deposit of $" + x + "." + " " + "Current balance is $" + str(USER_BALANCE))
continue
elif answer== "withdraw" or answer== "Withdraw":
y= input("How much would you like to withdraw? ")
if float (y)<=USER_BALANCE:
USER_BALANCE -= float(y)
print ("Your new balance is: $" + str(USER_BALANCE))
accountfile.write("\n" + "Withdraw of $" + y + "." + " " + "Current balance is $" + str(USER_BALANCE))
continue
else:
print ("Cannot be done. You have insufficient funds.")
elif answer== "check balance" or answer== "Check Balance":
print ("$" + str(USER_BALANCE))
elif answer== "exit" or answer== "Exit":
print ("Goodbye!")
accountfile.close()
break
else:
print ("I'm sorry, that is not an option")
도와주세요. 나는 이것이 완전히 엉망이지만 어떤 도움을 주시면 감사하겠습니다.