我目前正试图弄清楚如何同时迭代列和行[如果可能]。或者想知道最好的方法是什么。我遇到的最大问题是以简单的方式创建带有浮点数的循环。我们的教授特别要求我们这样做,然后当我们必须填写基本上访问这些循环的其余信息时。他并不希望我们导入不同的库,并说我们有简单的方法可以做到这一点,但并没有给我们提供指导:/我们的表格应该格式化为:{{ 3}}
这就是我已经拥有的......
def main():
print("This program is used to analyze commercial real estate loans.")
#function variables
purchase_price = input("Please input original purchase price: ")
down_payment = input("Please input total down payment: ")
APR = float(input("Please input APR: "))
periods_year = input("Please input the number of payments per year: ")
term = float(input("Please input loan length in years: "))
first_payment = input("Please input date of first payment in form MM/DD/YYYY: ")
#seperating str
dates = first_payment.split('/')
day = int(dates[0])
month = int(dates[1])
year = int(dates[2])
#part 1 calculations with main variables
total_payments = float(term) * float(down_payment)
loan_amount = float(purchase_price) - float(down_payment)
total_amount = loanCalc(APR, periods_year, loan_amount, total_payments)
end_date = str(day) + "/" + str(month) + "/" + str(year + int(term))
total_interest = r*total_payments
#print("End day of loan : %s" %end_date) [do not need to print this right now]
#loancalc function
def loanCalc(APR, period_year, loan_amount, total_payments):
#interest charged per period
r = (APR)/(period_year)
#amount paid in each period
P = (r * loan_amount)/(1- (1+r) ** (-(total_payments)))
#amount paid over life of loan
final_value = (P * total_payments)
#remember to return not print
return final_value
#loan payment table part 3/table will display
def pmtOptions(APR,period_year, term,loan_amount):
#headers, each column will be 10
print("{0:^80}".format("Alternative Loan Payment Table"))
print("{0:^80}".format("=============================="))
print("{0:^80}".format("Interest Rates"))
#interest rate loop
##for APR in range(3,6):
## if APR == 3:
## print("3.25",)
## APR = 3.25
## while APR <= 5.75:
## APR +=.5
## print("{0:>3}".format(""),"{0:<3}".format(APR), end="")
#printing interest rate loop
print("{0:>10}".format(""),"{0:>10}".format("3.25%"),"{0:>10}".format("3.75%"),
"{0:>10}".format("4.25%"),"{0:>10}".format("4.75%"),"{0:>10}".format("5.25%"),
"{0:>10}".format("5.75%"),"{0:>10}".format("6.25%"))
#never ending column headings
print("{0:>10}".format("# Payments"),"{0:>10}".format("="*len("3.25%")),"{0:>10}".format("="*len("3.75%")),
"{0:>10}".format("="*len("4.25%")),"{0:>10}".format("="*len("4.75%")),"{0:>10}".format("="*len("5.25%")),
"{0:>10}".format("="*len("5.75%")),"{0:>10}".format("="*len("6.25%")))
#attempting calculations
#payments column
for term in range(12,37,6):
print("{0:^10}".format(term))
#column 1
for term in range(12,37,6):