If..else Program CLASS XII COMPUTER SCIENCE
If..else Program CLASS XII COMPUTER SCIENCE
Output:--
>>>
Enter first number:5
Enter second number:2
2 is the minimum number.
Output:--
>>>
Enter any number:-1
-1 is a negative number.
>>>
1 is a positive number.
>>>
0 is a zero.
Output:--
>>>
Enter any number:5
5 is odd number.
>>>
Enter any number:8
8 is even number.
6. Aim: Write a program to check whether a year is a leap year or not:
Output:--
>>>
Enter any character:s
s is an alphabet.
>>>
Enter any character:5
5 is not an alphabet.
8. Aim: Write a program to input any alphabet and check whether it is vowel or consonant:
Output:--
>>>
Enter any alphabet:g
g is a consonant.
>>>
Enter any alphabet:e
e is vowel
9. Aim: Write a program to input any character and check whether it is alphabet, digit or
special character:
10. Aim: Write a program to check whether a character is uppercase or lowercase alphabet:
ch=input("Enter any character:")
Output:--
>>>
Enter any character:f
f is a lowercase alphabet.
>>>
Enter any character:J
J is an uppercase alphabet.
11. Aim: Write a program to input week number and print week day.
output:--
>>>
Enter a week number:6
6 is friday.
Enter a week number:5
5 is thursday.
>>>
Enter a week number:7
7 is saturday.
>>>
Enter a week number:1
1 is sunday
12. Aim: Write a program to input month number and print number of days in month:
13. Aim: Write a program to input angles of a triangle and check whether triangle is valid or
not:
n1=int(input("Enter first angle:"))
n2=int(input("Enter second angle:"))
n3=int(input("Enter third angle:"))
sum=n1+n2+n3
if sum==180:
print("Triangle is valid.")
else:
print("Triangle is not valid.")
Output:--
>>>
Enter first angle:60
Enter second angle:60
Enter third angle:60
Triangle is valid.
>>>
Enter first angle:90
Enter second angle:45
Enter third angle:80
Triangle is not valid.
14. Aim: Write a program to input all sides of a triangle and check whether triangle is valid
or not.
output:--
>>>
Enter first angle:3
Enter second angle:4
Enter third angle:5
Triangle is valid.
15. Aim: Write a program to check whether the triangle is equilateral, isosceles or scalene
triangle.
import math
import math
print("For quadratic equation, ax**2+bx+c=0, enter coefficient below")
a=int(input("Enter a:"))
b=int(input("Enter b:"))
c=int(input("Enter c:"))
delta=b*b-4*a*c
if a==0:
print("Error")
print("Value of a should not be zero")
else:
if delta>0:
root1=(-b+math.sqrt(delta))/(2*a)
root2=(-b-math.sqrt(delta))/(2*a)
print("Roots are Real and Unequal")
print("Roots are:",root1,'and',root2)
elif delta==0:
root=-b/(2*a)
print("Roots are Real and Equal")
print("Roots are:",root1,'and',root2)
else:
print("Roots are complex and imaginery")
output:--
>>>
For quadratic equation, ax**2+bx+c=0, enter coefficient below
Enter a:1
Enter b:5
Enter c:2
Roots are Real and Unequal
Roots are: -0.4384471871911697 and -4.561552812808831
output:--
>>>
Enter cost price:20
Enter selling price:25
Profit
>>>
Enter cost price:10
Enter selling price:8
Loss
>>>
Enter cost price:15
Enter selling price:15
No profit no loss!
18. Aim: Write a program to input marks of five subjects Physics, Chemistry,
Biology mathematics and Computer.
Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
marks=phy+chem+bio+maths+comp
perc=(marks/500)*100
else:
output:--
>>>
19. Write a program to input basic salary of an employee and calculate its gross salary
according to following:
20. Aim: Write a programe to iput electricity unit charges and calculate bill according to the
given condition: