Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CHITTAGONG UNIVERSITY OF

ENGINEERING AND TECHNOLOGY

Department of Urban and Regional Planning


Course Name: Programming for Planners
Course ID: CSE 282

Experiment
Experiment Title
No.
Write a C program to input basic salary of an
employee and calculate gross salary according
02
to given conditions. Gross Salary = Basic
Salary + HRA + DA

Name: Norin Binte Khorshed Megha


Student ID: 2005028
Level: 2
Term: II
Date of Submission: 11th September, 2023
Title:
Write a C program to input basic salary of an employee and calculate gross salary according
to given conditions. Gross Salary = Basic Salary + HRA + DA

Objective:

1. To learn about the functions of “If”, “elif”, “else” and their conditions.
2. To apply the mathematical operations for solving complex decision problems in
Python.
3. To understand the uses of basic commands on Python.

Discussion:

Python is a high-level, interpreted programming language known for its simplicity and
readability. It is used for a wide range of applications, including web development, data
analysis, machine learning, scientific computing, automation, and more. With the methods one
can do any kind of calculations in Python that can be logical or mathematical. The logical
operations like If, elif and else are very essential while programing some basic function.

The task was to write a C program to input basic salary of an employee and calculate gross
salary according to given conditions. Gross Salary = Basic Salary + HRA + DA

 Basic Salary <= 10000 : HRA = 20%, DA = 80%

 Basic Salary is between 10001 to 20000 : HRA = 25%, DA = 90%

 Basic Salary >= 20001 : HRA = 30%, DA = 95%

As we know, if, elif, else are conditional statements that provide us with the decision making
that is required when we want to execute code based on a particular condition.

The if, elif, else statement used in Python helps automate that decision making process. The if
condition is considered the simplest of the three and makes a decision based on whether the
condition is true or not. If the condition is true, it prints out the indented expression.

If the condition is false, it skips printing the indented expression. The if-else condition adds an
additional step in the decision-making process compared to the simple if statement. The
beginning of an if-else statement operates similar to a simple if statement; however, if the

1
condition is false, instead of printing nothing, the indented expression under else will be
printed. The most complex of these conditions is the if- elif-else condition. When we run into
a situation where we have several conditions, we can place as many elif conditions as necessary
between the if condition and the else condition.

Source Code and Output:

For source code, we took a variable ‘a’ where any value can be given. Then the conditional
code was written using if, elif and else.

This code will find out final output of the basic salary depending on the range the given amount
falls in and if it doesn’t fall into any of them, the code will show invalid answer. The output
picture is given below.

2
Conclusion:

The if-else statement is used to execute both the true part and the false part of a given condition.
If the condition is true, the if block code is executed and if the condition is false, the else block
code is executed. But a coder can face some challenges like:

 It is important to follow some basic rules of coding like using brackets, using inverted
coma (“”) in appropriate place, using numeric and string values perfectly.
 The length should not be normally more than 8 characters.
 It should not be a keyword, but keyword can be a part of variable, such as int_type
could be a variable, but int couldn't function in that way.
 Python is case sensitive thus uppercase and lowercase are significant. F and f will not
be same variable.
 White spaces should be avoided.

---------------------------------------------------------------------------------------------------------------

You might also like