code:
a= 8
1. if-elif-else ladder in Python
if(a<3):
print("The value of a is greater than 3")
elif(a>13):
print("The value of a is greater than 13")
elif(a>7):
print("The value of a is greater than 7")
elif(a>17):
print("The value of a is greater than 17")
else:
print("The value is not greater than 3 or 7")
# 2. Multiple if statements
if(a<3):
print("The value of a is greater than 3")
if(a>13):
print("The value of a is greater than 13")
if(a>7):
print("The value of a is greater than 7")
if(a>17):
print("The value of a is greater than 17")
else:
print("The value is not greater than 3 or 7")
print("Done")
O/P:
The value of a is greater than 7
The value of a is greater than 7
The value is not greater than 3 or 7
Done
2.
a = 45
if(a<3):
print('The value of a is greater than 3')
elif(a<7):
print('the value of a is greater that 7')
elif(a>17):
print('the value of a is greater than 13')
else:
print('the value is not greater than 3 or 7')
b = 34
if(b>10):
print('the vlue of b is less than 10')
if(b>20):
print('the value of b is less than 20')
if(b>30):
print('the value of b is less than 30')
if(b<40):
print('the value of b is less than 40')
a = 22
if(a>9):
print('Greater')
else:
print('lesser')
O/P:
the value of a is greater than 13
the vlue of b is less than 10
the value of b is less than 20
the value of b is less than 30
the value of b is less than 40
Greater
3. or
age = int(input("Enter your age: "))
if(age>34 or age<56):
print("You can work with us")
else:
print("You cannot work with us")
O/P:
Enter your age: 23
You can work with us
4. IN
a = [45, 56, 6]
print(435 in a)
O/P:
False
5. if else optional
a = 6
if(a==7):
print("yes")
elif(a>56):
print("no and yes")
else:
print("I am optional")
O/P:
I am optional
6. Find greatest number out of 4 number
num1 = int(input("Enter number 1: "))
num2 = int(input("Enter number 2: "))
num3 = int(input("Enter number 3: "))
num4 = int(input("Enter number 4: "))
if(num1>num4):
f1 = num1
else:
f1 = num4
if(num2>num3):
f2 = num2
else:
f2 = num3
if(f1>f2):
print(str(f1) + " is greatest")
else:
print(str(f2) + " is greatest")
O/P:
>> Enter number 1: 25
Enter number 2: 47
Enter number 3: 69
Enter number 4: 40
69 is greatest
7. Pirnt pass or fail
sub1 = int(input("Enter first subject marks\n"))
sub2 = int(input("Enter second subject marks\n"))
sub3 = int(input("Enter third subject marks\n"))
if(sub1<33 or sub2<33 or sub3<33):
print("You are fail because you have less than 33% in one of the subjects")
elif(sub1+sub2+sub3)/3 < 40:
print("You are fail due to total percentage less than 40")
else:
print("Congatulations! You passed the exam")
O/P:
>> Enter first subject marks 25
Enter second subject marks 56
Enter third subject marks 45
You are fail because you have less than 33% in one of the subjects
8. spam or not spam
text = input("Enter the text\n")
if("make a lot of money" in text):
spam = True
elif("buy now" in text):
spam = True
elif("click this" in text):
spam = True
elif("subscribe this" in text):
spam = True
else:
spam = False
if(spam):
print("This text is spam")
else:
print("This text is not spam")
O/P:
>> click this
This text is spam
9. Lenth of name
a = input("Enter your name")
if(len(a)<10):
print("the character lenth is less than 10")
else:
print("the character lenth is more than 10")
O/P:
>> Enter your name avinash
the character lenth is less than 10
10. Marks Grade
marks = int(input('Enter your marks'))
a = marks
if (a>90):
print("your grade is Ex")
elif(a>80):
print("your grade is A+")
elif(a>70):
print("your grade is A")
elif(a>60):
print("your grade is B")
elif(a>50):
print("your grade is C")
elif(a>=40):
print("your grade is D")
else:
print("Sorry your fail in exam")
O/P:
>> Enter your marks 65
your grade is B
WHILE