当前位置: 首页>>代码示例>>Python>>正文


Python Account.withdraw方法代码示例

本文整理汇总了Python中account.Account.withdraw方法的典型用法代码示例。如果您正苦于以下问题:Python Account.withdraw方法的具体用法?Python Account.withdraw怎么用?Python Account.withdraw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在account.Account的用法示例。


在下文中一共展示了Account.withdraw方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAccount

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
class TestAccount(unittest.TestCase):
    def setUp(self):
        """Each test should start with a zero-balance account."""
        self.account = Account()
    
    def test_deposit(self):
        """Deposit of n items correctly increases balance."""
        self.account.deposit(1)
        self.assertEqual(self.account.balance, 1)
        
    def test_withdraw_less_than_balance(self):
        """Withdrawal less than balance correctly lowers balance."""
        self.account.deposit(2)
        amount = self.account.withdraw(1)
        self.assertEqual( (amount,self.account.balance), (1,1) )
        
    def test_withdraw_equal_to_balance(self):
        """Withdrawal equal to balance yields balance, sets balance to 0."""
        self.account.deposit(1)
        amount = self.account.withdraw(1)
        self.assertEqual( (amount,self.account.balance), (1,0) )

    def test_withdraw_more_than_balance(self):
        """Withdrawal more than balance yields balance, sets balance to 0."""
        self.account.deposit(1)
        amount = self.account.withdraw(2)
        self.assertEqual( (amount,self.account.balance), (1,0) )
开发者ID:mwulf,项目名称:dreidel_game,代码行数:29,代码来源:test_account.py

示例2: test_statement

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
def test_statement():
    checkingAccount = Account(CHECKING)
    savingsAccount = Account(SAVINGS)
    henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount)
    checkingAccount.deposit(100.0)
    savingsAccount.deposit(4000.0)
    savingsAccount.withdraw(200.0)
    assert_equals(henry.getStatement(),
                  "Statement for Henry" +
                  "\n\nChecking Account\n  deposit $100.00\nTotal $100.00" +
                  "\n\nSavings Account\n  deposit $4000.00\n  withdrawal $200.00\nTotal $3800.00" +
                  "\n\nTotal In All Accounts $3900.00")
开发者ID:malhilli,项目名称:abc-bank-python,代码行数:14,代码来源:customer_tests.py

示例3: main

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
def main():

	#scenario 1 test
	person1 = Account(0.35,1000)
	person1.withdraw(500,1)
	person1.calc_prin_bal_day(person1.bal_sheet,person1.dayPrin)
	interest=person1.apr_calc(person1.bal_sheet,person1.dayPrin)
	tot_payoff=person1.get_final_prin_bal(person1.dayPrin)+interest
	print "Scenario 1 Test:"
	print "Interest owed is $%05.2f"%(interest)
	print "Total Payoff amount is $%06.2f"%(tot_payoff)

	#scenario 2 test
	person2 = Account("35%",1000)
	person2.withdraw(500,1)
	person2.pay(200,15)
	person2.withdraw(100,25)
	
	person2.calc_prin_bal_day(person2.bal_sheet,person2.dayPrin)
	interest2=person2.apr_calc(person2.bal_sheet,person2.dayPrin)
	tot_payoff2=person2.get_final_prin_bal(person2.dayPrin)+interest2

	print "\nSecenario 2 Test:"
	print "Interest owed is $%05.2f"%(interest2)
	print "Total Payoff amount is $%06.2f"%(tot_payoff2)
开发者ID:shantanudev,项目名称:avant_line_of_credit,代码行数:27,代码来源:main.py

示例4: main

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
def main():
    """Runs program with account.py and general_functions.py.

    When the program starts, it asks the user for a username and a password. This will be the account the user will use
    for this program. Note: The full user back-end is not programmed yet and so the users info is not used/saved!

    """
    top_menu = "\n\nWelcome to the Banking Simulator!"
    top_spacer = "-" * len(top_menu)
    print("{}\n{}".format(top_menu, top_spacer))
    account = Account()

    while True:
        account.menu_screen()
        cmd = input("> ")

        if cmd == "help":
            menu_help()
        elif cmd == "account":
            account.account_bridge()
        elif cmd == "info":
            account.account_info()
        elif cmd == "deposit":
            account.deposit()
        elif cmd == "withdraw":
            account.withdraw()
        elif cmd == "open account":
            account.open_account()
        elif cmd == "close account":
            account.close_account()
        elif cmd == "save":
            save(account)
        elif cmd == "simulation":
            account.time_simulation()
        elif cmd[0].lower() == "q":
            break
        else:
            print("\nERROR: Input not valid!")
开发者ID:Kwistech,项目名称:BankingSimulator,代码行数:40,代码来源:main.py

示例5: test_withdraw_not_enough

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
 def test_withdraw_not_enough(self):
     a = Account()
     a.deposit(10.0)
     with pytest.raises(ValueError):
         a.withdraw(50.0)
开发者ID:coreyadkins,项目名称:codeguild,代码行数:7,代码来源:account_test.py

示例6: test_withdraw_enough

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
 def test_withdraw_enough(self):
     a = Account()
     a.deposit(100.0)
     a.withdraw(50.0)
     assert a.get_funds() == 50.0
开发者ID:coreyadkins,项目名称:codeguild,代码行数:7,代码来源:account_test.py

示例7: AccountTest

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import withdraw [as 别名]
class AccountTest(unittest.TestCase):

    def setUp(self):
        self.test_account = Account("Peter", 125, "$")

    def test_create_new_account(self):
        self.assertTrue(isinstance(self.test_account, Account))

    def test_create_new_account_without_argumnets(self):
        with self.assertRaises(TypeError):
            Account()

    def test_deposit_int_money_check_balance(self):
        self.test_account.deposit(100)
        self.assertEqual(self.test_account.balance(), 225)

    def test_deposit_float_money_check_balance(self):
        self.test_account.deposit(100.55)
        self.assertEqual(self.test_account.balance(), 225.55)

    def test_deposit_zero_money(self):
        with self.assertRaises(ValueError):
            self.test_account.deposit(0)

    def test_deposit_negative_money(self):
        with self.assertRaises(ValueError):
            self.test_account.deposit(-10)

    def test_deposit_negative_float_money(self):
        with self.assertRaises(ValueError):
            self.test_account.deposit(-10.55)

    def test_witdraw_money_less_than_balance_should_return_true(self):
        self.assertTrue(self.test_account.withdraw(10.5))

    def test_witdraw_money_more_than_balance_should_return_false(self):
        self.assertFalse(self.test_account.withdraw(2000))

    def test_witdraw_money_same_than_balance_should_return_false(self):
        self.assertFalse(
            self.test_account.withdraw(self.test_account.balance()))

    def test_print_account(self):
        self.assertEqual(
            str(self.test_account),
            "Bank account for Peter with balance of 125$")

    def test_int_account(self):
        self.assertEqual(int(self.test_account), 125)

    def test_transfer_money_to_another_account_with_different_currency(self):
        with self.assertRaises(TypeError):
            second_account = Account("Tosho", 100, "BGN")
            self.test_account.transfer_to(second_account, 25)

    def test_transfer_money_to_another_account_with_same_currency(self):
        second_account = Account("Tosho", 100, "$")
        transfer_result = self.test_account.transfer_to(second_account, 25)
        self.assertTrue(transfer_result)

    def test_transfer_more_money_than_balance_to_another_account_with_same_currency(self):
        second_account = Account("Tosho", 100, "$")
        transfer_result = self.test_account.transfer_to(second_account, 2220)
        self.assertFalse(transfer_result)

    def test_account_history_create_account(self):
        the_account = Account("Gogo", 125, "BGN")
        self.assertEqual(the_account.getHistory(), ['Account was created'])

    def test_account_history_deposit_money(self):
        self.test_account.deposit(100)
        self.assertEqual(self.test_account.getHistory(), ['Account was created', 'Deposited 100$'])

    def test_account_history_withdraw_money_should_succes(self):
        self.test_account.withdraw(25)
        self.assertEqual(self.test_account.getHistory(), ['Account was created', '25$ was withdrawed'])

    def test_account_history_withdraw_more_money_than_ballnace_should_failed(self):
        self.test_account.withdraw(225)
        self.assertEqual(self.test_account.getHistory(), ['Account was created', 'Withdraw for 225$ failed.'])

    def test_account_history_balance_check(self):
        self.test_account.balance()
        self.assertEqual(self.test_account.getHistory(), ['Account was created', 'Balance check -> 125$'])

    def test_account_history_int_check(self):
        int(self.test_account)
        self.assertEqual(self.test_account.getHistory(), ['Account was created', '__int__ check -> 125$'])
开发者ID:presian,项目名称:HackBulgaria,代码行数:90,代码来源:unit_test.py


注:本文中的account.Account.withdraw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。