Python Forum
Annuity function for school - syntax error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Annuity function for school - syntax error
#1
Basic question but I`m doing something wrong. When run (windows idle 3.8) I receieve name 'a' is not defined. Thanks for help.

def instalment(a,b,c):
return (a*(b/100/12))/(1-(1+(b/100/12)**-c))
a = int(input("loan amount:"))
b = int(input("annual interest rate:"))
c = int(input("repayment period in months:"))
print("Monthly instalment equals to:", instalment(a,b,c))
Reply
#2
I don't think so.  I just ran the code on windows using the same version of IDLE without an error.  The result is wrong because there is an error in the instalment calculation.  You should also allow entering a fractional interest rate.
Reply
#3
Unless, since indentation is lost, you have the line 
a = int(input("loan amount:"))
indented. If that is true it will be considered part of the function, so your call in the line that calls the function will not have  a value for a
Can't wait for them to fix the python tags....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,309 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 1,998 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,002 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Invalid syntax error, where? tucktuck9 2 3,417 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 3,141 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 4,037 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,240 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 2,432 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,068 Oct-19-2019, 01:40 AM
Last Post: jefsummers
  Adding a sqrt function syntax error and <build-in function sqrt> from tkinter import Kael 0 1,856 Oct-14-2019, 05:51 PM
Last Post: Kael

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020