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

Conditional statements

The document contains a series of Python programs that demonstrate the use of conditional statements. Each program addresses a specific task, such as checking if a number is positive, comparing two numbers, calculating discounts, and identifying the type of triangle based on side lengths. The examples illustrate various conditions and outputs based on user input.

Uploaded by

Prachi Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Conditional statements

The document contains a series of Python programs that demonstrate the use of conditional statements. Each program addresses a specific task, such as checking if a number is positive, comparing two numbers, calculating discounts, and identifying the type of triangle based on side lengths. The examples illustrate various conditions and outputs based on user input.

Uploaded by

Prachi Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAMS ON CONDITIONAL STATEMENTS

Q8. WAP to input a number and check it is positive or not.


Code:-
x=int(input("Enter a number:"))
if(x>0):
print(x,"is a positive number.")
else:
print(x,"is a negative number.")
Q9. WAP to input two numbers and check both are equal or not.
Code:-
x=int(input("Enter value of x:"))
y=int(input("Enter value of y:"))
if(x==y):
print(x,"=",y)
else:
print(x,"≠",y)
Q10. WAP to input an amount, if amount is greater than 8000 than calculate 5%
discount and display net amount.
Code:- x=int(input("Enter an amount")
If(x>=8000):
D=x*5/100
print("Net amount=",D, "/- ")
else:
print("Net amount=",x, "/-")
Q11. WAP to input an alphabet & check, it is an uppercase or lowercase.
Code:- x=input("Enter an alphabet")
if(x>='A' and x<='Z'):
print("alphabet is in uppercase")
else:
print("alphabet is in lowercase")
Q12. WAP to input an alphabet if it is in uppercase convert into lowercase & vice-versa.
Code:- x=input("Enter an alphabet")
if(ord(x)>=65 and ord(x)<=90):
a=(ord(x)+32)
print("in lowercase:",chr(a))
else:
a=(ord(x)-32)
print("in uppercase:",chr(a))
Q13. WAP to input an alphabet & check, whether it is a vowel or a consonant.
Code:- x=input("Enter an alphabet:")
if(x=='A' or x=='E' or x=='I' or x=='O' or x=='U' or x=='a' or x=='e' or x=='i' or x=='o' or x=='u'):

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.")

You might also like