Python-打印函数2.7的语法错误

2024-09-27 07:21:57 发布

您现在位置:Python中文网/ 问答频道 /正文

出于某种背景,我已经编程很多年了,但直到现在才真正接触到Python,我不确定这里出了什么问题,IDLE正在标记第24行(最后一行):

'''
 Test Cases
'''
balance = 4213
annualInterestRate = 0.2
monthlyPaymentRate = 0.04

'''
 Variables
'''
previousBalance = 0
monthlyInterestRate = 0
minMonthlyPayment = 0
totalPaid = 0

m = 1
while (m != 12):
    monthlyInterestRate = annualInterestRate / 12
    minMonthlyPayment = monthlyPaymentRate * previousBalance
    balance = (previousBalance - minMonthlyPayment) * (1 + monthlyInterestRate)
    totalPaid = totalPaid + minMonthlyPayment
    previousBalance = balance
    m += 1
print('Month: ' + str(m))
print('Minimum monthly payment: ' + str(minMonthlyPayment))
print('Total paid: ' + str(round(totalPaid, 2))
print('Remaining balance: ' + str(round(balance, 2)) #Flagging Here

如果有人知道为什么最后一个打印功能会导致任何问题,请告诉我。


Tags: 标记test编程背景printbalanceidlestr
2条回答

作为提示,下次不要在2.7中的print函数周围加括号。工作效率不高。它也能消除这种困惑,我知道,因为它总是发生在我身上。但是,您应该在3.x中完成

你在第23行末尾漏掉了一个括号。

相关问题 更多 >

    热门问题