We help IT Professionals succeed at work.
Get Started

Python compiler throwing an error while executing the program ca not defined

sam_2012
sam_2012 asked
on
105 Views
Last Modified: 2020-03-24
Hi Team,

Iam trying to run the below code in python , Iam getting an error while calculating the ca value .Kindly help me with the casue of the error
''' write a program to calulate the gross salary of the employee
if his basic salary less than 2000 then HRA 10% of basic salary
DA 90% of basic salary , ca=10
> 2000 , hra 5%  bs and da 20 percent of basic salary '''

basicSalary=int(input("Enter the basic salary"))
if basicSalary < 2000:
      hra=basicSalary * 0.1
      da=basicSalary * 0.9
      ca=10
else:
      hra=basicSalary * 0.05
      da=basicSalary * 0.2

grossSalary=basicSalary+hra+da+ca
print (" the gross salary of employees is ",grossSalary)


C:\Users\sam\Desktop\MyPythonPrograms>python mypythonIf3.py
Enter the basic salary2300
Traceback (most recent call last):
  File "mypythonIf3.py", line 15, in <module>
    grossSalary=basicSalary+hra+da+ca
NameError: name 'ca' is not defined
Comment
Watch Question
Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE