Conditional statements
Conditional statements
print("alphabet is a vowel")
else:
print("alphabet is a consonant")
Q14. WAP to input a number & check its range as follows:-
1-10 = “range b/w 1 to 10”
11-20 = “range b/w 11 to 20”
21-30 = “range b/w 21 to 30”
Above 30 = “out of range”
Code:- x=int(input("Enter a number:"))
if(x>=1 and x<=10):
print("range b/w 1 to 10")
elif(x>=11 and x<=20):
print("range b/w 11 to 20")
elif(x>=21 and x<=30):
print("range b/w 21 to 30")
else:
print("out of range")
Q15. WAP to input a character & check it is an alphabet, digit, or symbol.
Code:- x=input("Enter a character:")
if(x>='A' and x<='Z' or x>='a' and x<='z'):
print("it is an alphabet")
elif(x>='0' and x<='9'):
print("it is a digit")
else:
print("it is a symbol")
Q16. WAP to input 3 sides of a triangle & check it is equilateral, isosceles, or
scalene triangle.
Code:-
x=int(input("Enter First side:"))
y=int(input("Enter Second side:"))
z=int(input("Enter Third side:"))
if(x==y and y==z):
print("triangle is equilateral")
elif(x==y or y==z or z==x):
print("triangle is isosceles")
elif(x!=y and y!=z and z!=x):
print("triangle is scalene")
Q17. WAP to input 3 numbers & find smallest.
Code:-
x=int(input("Enter first number:"))
y=int(input("Enter second number:"))
z=int(input("Enter third number:"))
if(x<y and x<z):
print(x,"is the smallest number.")
elif(y<x and y<z):
print(y,"is the smallest number.")
else:
print(z,"is the smallest number.")
Q18. WAP to input a no. & check it is a single digit, double digit, or triple digit.
Code:-
x=int(input("Enter a number:"))
if(x>=0 and x<=9):
print("number is single digit.")
elif(x>=10 and x<=99):
print("number is double digit.")
elif(x>=100 and x<=999):
print("number is triple digit.")
Q19. WAP to input 4 subject marks of a student & display total, percentage, &
grade as follows:-
Above 90 = grade ‘A’
Above 80 = grade ‘B’
Above 70 = grade ‘C’
Above 60 = grade ‘D’
Else = grade ‘E’
Code:-
phy=int(input("Enter physics marks:"))
che=int(input("Enter chemistry marks:"))
bio=int(input("Enter biology marks:"))
math=int(input("Enter mathematics marks:"))
T=phy+che+bio+math
P=T*100/280
print("total Marks=",T,"/280")
print("total Percentage=",P,"%")
if(P>=90):
print("Grade=A")
elif(P>=80):
print("Grade=B")
elif(P>=70):
print("Grade=C")
elif(P>=60):
print("Grade=D")
else:
print("Grade=E")
Q20. WAP to input a number if number is positive than input another number, if
second number is even than do the addition otherwise print a message.
Code:-
x=int(input("Enter first number:"))
if(x>0):
y=int(input("Enter second number:"))
if(y%2==0):
z=x+y
print("addition of",x,"&",y,"=",z)
else:
print(y,"is not even.")
else:
print(x,"is not positive.")