‘if condition’ program
1. Write a program to show greater number from given 2 numbers.
2. WAP to accept a number from 1 to 7 and display the name of the day like 1 for Sunday, 2 for Monday
and so on.
3. Write a program to check whether a person is eligible for voting or not. (accept age from user)
4. WAP to check whether a person is senior citizen or not.
5. WAP to accept two numbers and mathematical operators and perform operation accordingly.
Enter 1st Number: 1
Enter 2nd Number: 19
Enter Operator: +
Your answer is: 20
6. WAP to check whether a number is positive or negative.
7. Accept the temperature in degree Celsius of water and check whether it is boiling or not. (Boiling point of
water in 1000C.
8. Accept any city from user and display monument of that city.
City Monument
Delhi Red Fort
Agra Taj Mahal
Jaipur Jal Mahal
9. WAP to check whether a year is leap year or not.
10. Write a program to check whether a number is divisible by 7 or not.
11. WAP to accept percentage and display the 12. WAP to accept % from the user and display
category according to the following criteria. the grade according to the following criteria.
Percentage Category Marks Grade
>=65 Excellent >90 A
>= 55 Good >80 and <=90 B
>=40 Fair >=60 and <=80 C
<40 Faild Below 60 D
13. WAP to display “Hello!” if a number entered by user is multiple of five, otherwise print “Bye”
14. WAP to display the last digit of a number.
15. WAP to check whether a number entered by user is even or odd.
16. WAP to check whether the last digit of a number is divisible by 3 or not.
17. WAP to accept the cost price of a bike and 18. WAP to calculate electricity bill (accept number of
display the road tax to be paid according to the units from user) according the following criteria:
following criteria: Unit Price
Cost Price (in Rupees) Tax First 100 units no charge
>1,00,000 15% Next 100 units Rs. 5 per unit
>50,000 and <= 1,00,000 10% After 200 units Rs. 10 per unit
<= 50,000 5% (For example, if input unit is 350 than total bill
amount is Rs. 2000.)
19. Accept the following from the user and calculate the percentage of class attended:
a. Total number of working days:
b. Total number of days for absent:
After calculating percentage show that, if the percentage is less than 75, than student will not be able to sit
in exam.
21. Accept the number of number of days from the user and calculate the charge for library according to
following:
Till five days : Rs. 2 per day
Six to ten days : Rs. 3 per day
11 to 15 days : Rs. 4 per day
After 15 days : Rs. 5 per day
22. Accept the kilometres covered and calculate the bill according to the following criteria:
First 10 Km : Rs. 11 per km
Next 90 Km : Rs. 10 per km
After that : Rs. 9 per km
AND/OR
23. Accept 3 sides of a triangle and check whether it is an equilateral, isosceles or Scalene triangle.
Note:
a. An equilateral triangle is a triangle in which all 3 sides are equal.
b. A scalene triangle is a triangle that has 3 inequal sides.
c. An isosceles triangle is a triangle with (at least) two equal sides.
24. WAP to check whether a number entered is three-digit number or not.
25. WAP to check whether a number accepted from user is divisible by 2 and 3 both.
26. WAP to find the smallest number out of 3 numbers entered by the user.
27. Accept the age of 4 people and display the youngest one?
28. Accept the marks of English, Maths and Science, Social Studies Subject and display the stream allotted
according to following:
All Subjects more than 80 marks – Science Stream
English > 80 and maths, Science above 50 – Commerce Stream
English > 80 and Social Studies > 80 - Humanities
29. A company decided to give bonus to employee 30. Accept the marked price from the user and
according to following criteria: calculate the Net amount as (Marked Price –
Time period of Service Bonus Discount) to pay according to the following
More than 10 years 10% criteria:
>=6 and <=10 8% Market Price Discount
Less than 6 years 5% >10000 20%
Ask user for their salary and years of service >7000 and <=10000 15%
and print the net bonus amount. <=7000 10%
Use of in
31. Write a program to check a character is vowel or not. Hint: if ch in “AEIOUaeiou”
Theory
1. Name the keyword which helps in writing code involves condition.
Ans. If
2. Writ the syntax of simple if statement.
Ans.
if condition:
statement 1
statement 2
statement 3
.
.
Statement n
3. Is there any limit of statement that can appear under an if block.
Ans. No
4. What do you mean by statement?
Ans. Executable lines in program is called instruction.
5. Write the output of the following:
if True:
print(101)
else:
print(202)
Ans. 101
Q6. Write the logical expression for the following: A is greater than B and C is less than D
Ans. A > B and C < D
Q7. Write the output of the following if a = 9.
if (a > 5 and a <= 10):
print (“Hello!”)
else:
print (“Bye”)
Ans. Hello!
Q.8 __________ is a graphical representation of steps (algorithm / flow chart)
Ans. Flow Chart
Q.10 Python has ______________ statement as empty statement (Pass/Fail)
Ans. Pass
Q.11 In Python, a block is a group of ___________ statement having same identical level. (consecutive/alternate)
Ans. Consecutive
Q.12 Out of “elif” and “else if”, which is the correct statement in python?
Ans. elif
Q.13 What is the purpose of else in if-elif ladder?
Ans. if none of the condition is true in if-elif ladder then the else part will execute.
Q.14 Consider the following code:
if i < j:
if j < k:
i=j
else:
j=k
else:
if j > k:
j=i
else:
i=k
print (i,j,k)
What will the above code print if the variables i, j and k have the following values?
a. i = 3, j = 5 and k = 7 b. i = -2, j = 5 and k = 9 c. i = 8, j = 15 and k = 12
d. i = 13, j = 15 and k = 13 e. i = 3, j = 5 and k f. i = 25, j = 15 and k = 17
Q.15 Evaluate the following statements:
Code Output
a, b, c, d = True, True, True, True
print(c) True
print(d) True
print(not a) False
print(not b) False
print(not c) False
print(not d) False
print(a and b) True
print(a or b) True
print(a and c) True
print(a or c) True
print(a and d) True
print(a or d) True
print(b and c) True
print(b or c) True
print(a and b or c) True
print(a or b and c) True
print(a and b and c) True
print(a or b or c) True
print(not a and b and c) False
print(not a or b or c) True
print(not(a and b and c)) False
print(not(a or b or c)) False
print(not a and not b and not c) False
print(not a or not b or not c) False
print(not(not a or not b or not c)) True