我已经让代码工作了一次,但是所有变量都是整数,这意味着它们中没有一个是小数。这就是我现在所拥有的,我一直在犯错误:
input = 'John Doe 4893.27'
account = str(input)
account = account.split()
first_name = account[0]
last_name = account[1]
i_deposit = account[2]
i_deposit = float(i_deposit)
i_deposit = '{:.2f}'.format(i_deposit)
new_amount = 0
fee = 0
d = 0
w = 0
def Deposit(d):
d = float(d)
d = '{:.2f}'.format(d)
d = bin(d)
new_amount = bin(i_deposit) + d
new_amount = bin(new_amount)
return bin(new_amount)
def Withdraw(w):
w = float(w)
w = '{:.2f}'.format(d)
w = bin(w)
new_amount = bin(i_deposit) + w
new_amount = bin(new_amount)
return bin(new_amount)
def FeeCalc(money):
money = float(i_deposit)
if money <= 1000:
fee = 10
else:
fee = 0
fee = '{:.2f}'.format(fee)
return fee
i = 0
def Interest(i):
i = float(i_deposit)
i = int(i)
i = i * .03
i = '{:.2f}'.format(i)
return i
dep_amount = Deposit(d)
wit_amount = Withdraw(w)
net_amount = sum(dep_amount, wit_amount)
new_amount = int(new_amount)
int_fee = Interest(i)
Withdraw(276.84)
print(first_name, last_name, 'account information:', '\nInitial deposit: $', i_deposit, '\nNew balance: $', new_amount, '\nFee: $', fee, '\nInterest: $', int_fee)最近我似乎无法修复的错误是:
Traceback (most recent call last):
File "/Users/shardae/PycharmProjects/HW1/main.py", line 55, in <module>
dep_amount = Deposit(d)
File "/Users/shardae/PycharmProjects/HW1/main.py", line 23, in Deposit
d = bin(d)
TypeError: 'str' object cannot be interpreted as an integer
Process finished with exit code 1发布于 2022-07-12 19:03:27
当您使用“{:.2F}‘.format(Some_variable)”函数时,实际上是将指定值的任何变量转换为字符串。我不相信那是你想要的。在此之后,让我对您的程序进行一些修改,以保持代码的精神。
input = 'John Doe 4893.27'
account = str(input)
account = account.split()
first_name = account[0]
last_name = account[1]
i_deposit = float(account[2])
def Deposit(amount, d):
amount = amount + d
return amount
def Withdraw(amount, w):
w = (int(w) * 100) / 100 # Example of insuring precision to two decimal places
amount = amount - w
return amount
def FeeCalc(money):
fee = 0
if money <= 1000.00:
fee = 10
return fee
def Interest():
i = float(i_deposit)
i = int(i)
i = i * .03
return i
new_amount = i_deposit # Set the work field to the initial deposit balance
int_fee = Interest() # Calculate interest and add it to the balance
new_amount += int_fee
new_amount = Withdraw(new_amount, 276.84) # Calculate the new balance once the withdrawal amount is applied
fee = FeeCalc(new_amount) # Subtract any bank fee if the balance has dropped below $1000.00
new_amount -= fee
print(first_name, last_name, 'account information:', '\nInitial deposit: $', '{:.2f}'.format(i_deposit), '\nNew balance: $', '{:.2f}'.format(new_amount), '\nFee: $', fee, '\nInterest: $', int_fee)代码仍然使用浮点变量。但是,只有在打印输出中才会发生两个小数点的特定格式设置。
继续回顾这些调整,看看这是否满足了你的解决方案的精神。
希望这能有所帮助。
致以问候。
https://stackoverflow.com/questions/72956490
复制相似问题