简单的帐户计划 [英] Simple account program

查看:76
本文介绍了简单的帐户计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我仍然需要一些关于此代码的帮助,我已经进一步了解了

。感谢您的帮助。我想了解如何使用
使文件可搜索以及如何进行存款和取款

与交易类进行交互。

我只需要搜索文件中的存款和取款以及带有时间戳的帐户金额
。谢谢你的帮助。

帮助。


班级帐号:

def __init __(自我,初始):

self.balance = initial

def deposit(self,amt):

self.balance = self.balance + amt

def退出(自我,amt):

self.balance = self.balance - amt

def getbalance(self):

返回self.balance


类Transactoin:

def transaction(自我,

self.transaction =

导入时间

time.asctime()

raw_input(这是存款还是取款?)

如果撤回:

elif

raw_input(请在这里输入金额。)


类存款(交易):

def deposit(self,amt):

self.balance = self.balance + amt

def getbalance(个体经营):

返回自我.balance


班级提款(Trasaction):

def withdrawl(self,amt):

self.balance = self。巴兰ce - amt

def getbalance(个体经营):

返回self.balance

进口咸菜

pickle.dump ((撤回),档案(''account.pickle'',''w''))

pickle.dump((存款),档案(''account.pickle'','' w'')


打印你当前的帐户总数是。,self.balance

Hello all, I am still needing some help on this code, I have gone a bit
further on it. Thank you for the help. I am trying to understand how to
make the file searchable and how I am to make the deposit and withdrawl
interact with the transaction class.
I need to just search the file only for the deposits and withdrawls and
the amount in the account with a time stamp. Thank you for your
assistance.

class Account:
def __init__(self, initial):
self.balance = initial
def deposit(self, amt):
self.balance = self.balance + amt
def withdraw(self, amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance

class Transactoin:
def transaction(self,
self.transaction =
import time
time.asctime()
raw_input("Is this a deposit or withdrawl?")
if withdrawl:
elif
raw_input("Please enter amount here.")

class Deposit(Transaction):
def deposit(self, amt):
self.balance = self.balance + amt
def getbalance(self):
return self.balance

class Withdrawl(Trasaction):
def withdrawl(self, amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance
import pickle
pickle.dump ((withdrawl), file (''account.pickle'', ''w''))
pickle.dump ((deposit), file (''account.pickle'', ''w''))

print "Your current account total is.", self.balance

推荐答案

Igorati,

我希望我能给你一个简单的修复,但是......

你需要真正重新阅读文档并做首先是一些导师。

你对类和命名空间的理解是有缺陷的,如果没有进一步的学习,你就不会明白了。


搜索策略:

python名称空间

python类

python导师


类就像容器一样。

类具有自己的命名空间,self。

多个类不共享命名空间。

远离继承直到y你对命名空间有所了解,

无需混淆。

提款,存款,交易应该是账户类的成员。

这样他们就可以共享命名空间并简化你的设计。

为什么你需要搜索一个泡菜?

挑选一个类的实例并在需要时取消它你的

数据会在你的实例中。

如果你有真正的代码发布它,因为这段代码不起作用而且从不

将。

退出发布作业,你可以要求偶尔的帮助,但这是我第三次看到这个,这是越来越糟糕你已经

之前警告过;)

肯定在你第一次问你的那个月你可以阅读一些

文件。

#这个不完整甚至测试它只是一个例子(基于

你的代码)

导入时间

类帐户:

def __init __(自我,初始):

self.balance = initial

self.history = {}


def deposit(self,amt):

self.balance = self.balance + amt

self.save(''deposit'',amt)


def退出(自我,amt):

self.balance = self.balance - amt

self.save(''withdrawl'',amt)


def getbalance(个体经营):

返回self.balance

def gethistory(个体经营):

返回self.history


def save(self,trans,amount):

#存储交易类型,金额,余额

self.history [self.timestamp()] =(trans,amount,self.balance)


def timestamp(self):

返回时间。 asctime()


def transaction(self):

withdrawl = raw_input(这是存款还是取款?)

amount = raw_input(请在此处输入金额。)
如果在[" withdrawl",w]中撤回.lower()


self.withdraw(金额)

否则:

self.deposit(金额)

hth,

MEFarmer

Igorati,
I wished I could give you a simple fix, BUT...
You need to really re-read the docs and do some tutors first .
Your understanding of classes and namespaces is flawed and will not
become clear without futher study.

search strategy:
python namespaces
python class
python tutor

Classes are like containers.
Classes have there own namespace, "self".
Multiple classes do not share namespaces.
Stay away from inheritance till you have an understanding of namespace,
no need in getting mixed up.
Withdrawl, Deposit, Transaction should be members of the account class.
That way they can share a namespace and simplify your design.
Why do you need to search a pickle?
Pickle an instance of the class and unpickle it when needed and your
data will be however it was in your instance.
If you have real code post it because this code does not work and never
will.
Quit posting homework, you can ask for occasional help, but this is the
third time i have seen this, it is getting worse and you have been
warned before ;)
Surely in the month since you first asked you could have read a bit of
documentation.
# this is not complete or even tested it is just an example ( based on
your code )
import time
class Account:
def __init__(self, initial):
self.balance = initial
self.history = {}

def deposit(self, amt):
self.balance = self.balance + amt
self.save(''deposit'',amt)

def withdraw(self, amt):
self.balance = self.balance - amt
self.save(''withdrawl'', amt)

def getbalance(self):
return self.balance

def gethistory(self):
return self.history

def save(self,trans,amount):
# store the transaction type, amount, balance
self.history[self.timestamp()] = (trans,amount,self.balance)

def timestamp(self):
return time.asctime()

def transaction(self):
withdrawl = raw_input("Is this a deposit or withdrawl?")
amount = raw_input("Please enter amount here.")
if withdrawl.lower() in ["withdrawl","w"]:
self.withdraw(amount)
else:
self.deposit(amount)
hth,
M.E.Farmer


Igorati写道:
Igorati wrote:
大家好,我仍然需要一些关于此代码的帮助,我已经进一步了解它。感谢您的帮助。我正在努力了解如何使文件可搜索以及如何使存款和取款与交易类进行交互。
我只需要搜索存档的文件并带有时间戳的帐户中的金额。感谢您的帮助。
Hello all, I am still needing some help on this code, I have gone a bit
further on it. Thank you for the help. I am trying to understand how to
make the file searchable and how I am to make the deposit and withdrawl
interact with the transaction class.
I need to just search the file only for the deposits and withdrawls and
the amount in the account with a time stamp. Thank you for your
assistance.




您好Igorati,


在我编写的分类帐程序中,我设置了帐户类如下面的

。我不确定你在搜索文件时的意思。您是否正在尝试读取现有文件?


类交易:

def __init __(自我):

self.name =''''

self.amount = 0.0

self.type =''''


类帐号:

def __init __(self,name =''''):

self.name = name

self .ledger = []


def newtransaction(self,name,amount,type):

transaction = Transaction()

transaction.name = name

transaction.amount =金额

transaction.type =''''

self.ledger.append(交易)


def getbalance(个体经营):

余额= 0.0

用于self.ledger的交易:

余额+​​ = transaction.amount

返还余额


#在你的主程序中某处。

myaccount =账户(' '储蓄账户'')


#从用户或文件获取交易数据

name = ''现金''

金额= 20.0

type =''deposite''

myaccount.newtransaction(名称,金额,类型)


print"%s Balance is



Hi Igorati,

In a ledger program I wrote, I setup the account classes something like
below. I''m not sure what you mean by searching a file. Are you trying
to read an already existing file?

class Transaction:
def __init__(self):
self.name = ''''
self.amount = 0.0
self.type = ''''

class Account:
def __init__(self, name=''''):
self.name = name
self.ledger = []

def newtransaction(self, name, amount, type):
transaction = Transaction()
transaction.name = name
transaction.amount = amount
transaction.type = ''''
self.ledger.append(transaction)

def getbalance(self):
balance = 0.0
for transaction in self.ledger:
balance += transaction.amount
return balance

# Within your main program somewhere.
myaccount = Account( ''Savings Account'')

# get transaction data from user or file
name = ''cash''
amount = 20.0
type = ''deposite''
myaccount.newtransaction( name, amount, type)

print "%s Balance is


%。2f" %(myaccount.name,myaccount.getbalance())

%.2f" % (myaccount.name, myaccount.getbalance())


这篇关于简单的帐户计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆