【发布时间】:2015-08-15 15:36:27
【问题描述】:
我正在编写一个简单的程序,但我无法摆脱这个循环。我想要做的是,如果提款金额大于您的余额,请转到 while 循环。 while循环应该得到一个新的输入并检查新的输入是否大于平衡,如果它是重复的,如果不是就去else,这是我打印余额的地方
class Account(object):
balance = 0
accountNumber = 0
def __init__(self, f, l, ssn, b):
self.firstName = f
self.lastName = l
self.socialSecurity = ssn
self.balance = b
self.accountNumber = randint(0, 10000)
def __str__(self):
return self.firstName + " " + self.lastName + \
"'s balance is $" + str(self.balance) + \
". Your account Number is " + str(self.accountNumber)
def deposit(self, amount):
depositAmount = amount
balance = self.balance + depositAmount
print(str(depositAmount) + " has been deposited into account "
"#" + str(
self.accountNumber) + " Your balance is "
"now " + str(balance))
return self.balance
def withdraw(self, amount):
withdrawAmount = amount
balance = self.balance - withdrawAmount
if float(withdrawAmount) > float(balance):
while float(withdrawAmount) > float(balance):
print("Insufficient Funds, Enter new amount")
withdrawAmount = raw_input(">")
else:
print(str(withdrawAmount) + " has been taken out of account "
"#" + str(
self.accountNumber) + " Your balance is "
"now " + str(balance))
testOne = Account("John", "Smith", "1111", 1000)
print(testOne)
print(testOne.accountNumber)
testOne.deposit(200)
testOne.withdraw(5000)
我的问题是,无论我说什么输入新金额,我都被困在 while 循环中
【问题讨论】:
-
这是stackoverflow.com/questions/20449427/…的间接欺骗...阅读你会明白的
-
我的循环或输入有问题吗?
-
balance的值是多少?您是在提供100之类的输入,还是包含其他符号?你能举一个输入和balance的值的例子吗?错误是可重复的? -
在所有的编辑之后,我仍然卡在我的 while 循环中
标签: python python-2.7 loops while-loop