0% found this document useful (0 votes)
2 views

If ,else and elif condition statements

The document discusses the use of if, else, and elif statements in Python through examples of simple and compound interest calculations. It also highlights common errors such as indentation issues and provides a set of questions for practice related to conditional statements. The questions cover various scenarios including salary calculations, discounts, student divisions based on percentage marks, and insurance eligibility for drivers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

If ,else and elif condition statements

The document discusses the use of if, else, and elif statements in Python through examples of simple and compound interest calculations. It also highlights common errors such as indentation issues and provides a set of questions for practice related to conditional statements. The questions cover various scenarios including salary calculations, discounts, student divisions based on percentage marks, and insurance eligibility for drivers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

If ,else and elif condition statements.

First Program:

p=int(input("Enter the principle amount="))


n=int(input("Enter the value of year="))
if p>1000:
r=0.02
else:
r=0.5
si=(p*n*r)/100
print("Therefore simple interest is given as=" +str(si))

OutPut:
Enter the principle amount=2000
Enter the value of year=1
Therefore simple interest is given as=0.4

Second Program:

Error:(IndentationError: unexpected indent)

# calculation of compound interest by using if else statements


p=int(input("Enter the value of principle="))
n=int(input("Enter the value of Year"))
if p>10000:
i=2.0
else:
i=1.5
A=p*pow(1+i,n)
ci=A-p
print("Hence compound interest is = Rs." + str(ci))
print("Accumulated amount is =" + str(A))

Output:
ERROR!
File "<string>", line 22
print("Accumulated amount is =" + str(A))
IndentationError: unexpected indent

Correct syntax (Coding)


# calculation of compound interest by using if else statements
p=int(input("Enter the value of principle="))
n=int(input("Enter the value of Year"))
if p>10000:
i=2.0
else:
i=1.5
A=p*pow(1+i,n)
ci=A-p
print("Hence compound interest is = Rs." + str(ci))
print("Accumulated amount is =" + str(A))

Output:
If p=20000
Enter the value of principle=20000
Enter the value of Year1
Hence compound interest is = Rs.40000.0
Accumulated amount is =60000.0

Or if p=9000
Enter the value of principle=9000
Enter the value of Yaer1
Hence compound interest is = Rs.13500.0
Accumulated amount is =22500.0

Question set
1. If his basic salary is less than Rs. 1500, then HRA=10% of basic salary and DA =90% of
basic salary. If his salary is either equal to or above Rs.1500, then HRA= Rs. 500 and
DA =98% of basic salary. If the employee’s salary is input through the keyboard, write a
program to find his gross salary.
2. While purchasing certain items, a discount of 10% is offered if the quantity purchased is
more than 1000. If quantity and price per item are input through the keyboard, write a
program to calculate the total expenses.
3. Percentage marks obtained by a student are input through the keyboard. The student
gets a division as per the following rules:
● Percentage above or equal to 60 - First division
● Percentage between 50 and 59 - Second division
● Percentage between 40 and 49 - Third division
● Percentage less than 40 - Fail
Write a program to calculate the division obtained by the students.
4. A company insures its drivers in the following cases:
● If the driver is married.
● If the driver is unmarried, male & above 30 years of age.
● If the driver is unmarried, female & above 25 years of age.
In all other cases, the driver is not insured. If the marital status, sex and age of the
driver are the inputs, write a program to determine whether the driver should be insured
or not.
5. Write conditional expression for
● If a<10 b=20, else b=30
● Print ‘morning ‘ if time < 12, otherwise print ‘Afternoon’
● If marks >=70, set remarks to true, otherwise False
6. Rewrite the following code snippet in 1 line:
x=3
y = 3.0
If x==y:
print(“x and y are equal’)
else:
print(“a and y are not equal”)
7. Write the output of the following program
1) a=10
If a =30 or 40 or 60:
print(“Hello”)
else:
print(“Hi“)

You might also like