How do I sum the total calculated values in a loop (Python 2.7) -
i trying sum total yearly rent period, using code shown below.
any appreciated.
rent_rate = input('please enter price per square foot:') # price sq/ft lease_rate = input('please enter rate of lease:') # interest rate lease_term = input('please enter tenor (in years) of lease:') size_of_space = input('please enter size(in square feet) of space:') print "year %25s" % "rent rate%25s" % "rate%25s" % "square feet%25s" % "yearly rent%25s" % "monthly rent" year in range( 0, lease_term ): rent_rate = principal * ( 1.0 + rate ) ** year yearly_rent = rent_rate * size_of_space monthly_rent = yearly_rent/12 print "%4d%21.2f%21.2f%21.2f%21.2f%21.2f" % ( year + 1, rent_rate, rate, size_of_space, yearly_rent, monthly_rent)
i think need few things! should assign 'principal' 'rent_rate' because came out of thin air!
also, if user inputs going numbers, should 'int' or 'float' of inputs! here:
rent_rate = float(input('please enter price per square foot:')) lease_rate = float(input('please enter rate of lease:')) lease_term = int(input('please enter tenor (in years) of lease:')) size_of_space = float(input('please enter size(in square feet) of space:')) print "year %25s" % "rent rate%25s" % "rate%25s" % "square feet%25s" % "yearly rent%25s" % "monthly rent" year in range(0, lease_term): rent_rate = principal * ( 1.0 + rate ) ** year yearly_rent = rent_rate * size_of_space monthly_rent = yearly_rent/12 print "%4d%21.2f%21.2f%21.2f%21.2f%21.2f" % ( year + 1, rent_rate, rate, size_of_space, yearly_rent, monthly_rent)
and style thing--the in-line comments should done sparingly. check out python pep 8 style guide!
Comments
Post a Comment