You are on page 1of 11

ASSIGNMENT2 IF-ELSE STATEMENT

# find number of days in given month

m = int(input("Enter month in number :"))


if m in [1,3,5,7,8,10,12]:
print('31 days')
elif m in [4,6,9,11]:
print('30 days')
elif m == 2:
y = int(input('Enter the year :'))
if y%4 == 0:
print('29 days')
else:
print('28 days')
else:
print('ERROR = INVALID MONTH')

Enter month in number :5


31 days
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find number of days in given month.py
Enter month in number :4
30 days
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find number of days in given month.py
Enter month in number :2
Enter the year :2000
29 days
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find number of days in given month.py
Enter month in number :2
Enter the year :2005
28 days
>>>
# find area

print("CHOICES FOR AREA")


print("c----area of circle")
print("r----area of rectangle")
print("s----area of square")
ch = input("Enter your choice")
if ch in 'cC':
r = float(input("Enter the radius :"))
area = 3.14*r**2
print("\n Area of circle = ",area)
elif ch in 'rR':
l = float(input("Enter the length of rectangle :"))
b = float(input("Enter the breadth of rectangle :"))
area = l*b
print("\n Area of rectangle =",area)
elif ch in 'sS':
a = float(input("Enter the side of square :"))
area = a*a
print("\n Area of square =",area)
else:
print("\n Invalid Code")

CHOICES FOR AREA


c----area of circle
r----area of rectangle
s----area of square
Enter your choicec
Enter the radius :49

Area of circle = 7539.14


>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find area of circle, rectangle, square.py
CHOICES FOR AREA
c----area of circle
r----area of rectangle
s----area of square
Enter your choicer
Enter the length of rectangle :57
Enter the breadth of rectangle :45

Area of rectangle = 2565.0


>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find area of circle, rectangle, square.py
CHOICES FOR AREA
c----area of circle
r----area of rectangle
s----area of square
Enter your choices
Enter the side of square :24

Area of square = 576.0


>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find area of circle, rectangle, square.py
CHOICES FOR AREA
c----area of circle
r----area of rectangle
s----area of square
Enter your choicev

Invalid Code
>>>
# percentage and grade of student

a = int(input("Enter your marks in Physics: "))


b = int(input("Enter your marks in Chemistry: "))
c = int(input("Enter your marks in IP: "))
d = int(input("Enter your marks in English: "))
e = int(input("Enter your marks in Biology: "))
p = (a+b+c+d+e)/5
print('Percentage: ',p,'%')
if p>=90:
grade = 'A'
elif p>=80 and p<90:
grade = 'B'
elif p>=70 and p<80:
grade = 'C'
elif p>=60 and p<70:
grade = 'D'
else:
grade = 'E'
print('GRADE: ',grade)

Enter your marks in Physics: 97


Enter your marks in Chemistry: 94
Enter your marks in IP: 95
Enter your marks in English: 91
Enter your marks in Biology: 98
Percentage: 95.0 %
GRADE: A
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\percentage and grade of a student.py
Enter your marks in Physics: 87
Enter your marks in Chemistry: 89
Enter your marks in IP: 86
Enter your marks in English: 82
Enter your marks in Biology: 85
Percentage: 85.8 %
GRADE: B
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\percentage and grade of a student.py
Enter your marks in Physics: 76
Enter your marks in Chemistry: 78
Enter your marks in IP: 77
Enter your marks in English: 73
Enter your marks in Biology: 79
Percentage: 76.6 %
GRADE: C
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\percentage and grade of a student.py
Enter your marks in Physics: 67
Enter your marks in Chemistry: 69
Enter your marks in IP: 66
Enter your marks in English: 65
Enter your marks in Biology: 63
Percentage: 66.0 %
GRADE: D
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\percentage and grade of a student.py
Enter your marks in Physics: 57
Enter your marks in Chemistry: 55
Enter your marks in IP: 59
Enter your marks in English: 53
Enter your marks in Biology: 58
Percentage: 56.4 %
GRADE: E
>>>
# percentage and grade of a student

p = int(input('Enter the principle :'))


t = int(input('Enter the time in yrs :'))
if t>=5:
r = 7.8
elif t>=1 and t<5:
r = 4.5
else:
r=3
si = p*r*t/100
amt = si + p
print('SIMPLE INTEREST :',si)
print('AMOUNT :',amt)

Enter the principle :46400


Enter the time in yrs :6
SIMPLE INTEREST : 21715.2
AMOUNT : 68115.2
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\calculate si and amount.py
Enter the principle :46400
Enter the time in yrs :1
SIMPLE INTEREST : 2088.0
AMOUNT : 48488.0
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\calculate si and amount.py
Enter the principle :46400
Enter the time in yrs :0
SIMPLE INTEREST : 0.0
AMOUNT : 46400.0
>>>
# leap year check

y = int(input("Enter the year :"))


if y%4 == 0 and y%100 != 0:
print(y, "is a leap year")
elif y%400 == 0:
print(y, "is a leap year")
elif y%100 == 0:
print(y, "is not a leap year")
else:
print(y, "is not a leap year")

Enter the year :2000


2000 is a leap year
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\leap year check.py
Enter the year :2015
2015 is not a leap year
>>>
# find bigger number

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))
if a>b:
print(a,'is bigger than',b)
elif b>a:
print(b,'is bigger than',a)
else:
print('Numbers are equal')

Enter first number: 726


Enter second number: 546
726.0 is bigger than 546.0
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\find bigger number.py
Enter first number: 324
Enter second number: 655
655.0 is bigger than 324.0
>>>
#addition, multiplication, subtraction
print('PRESS FOR')
print('+ Addition')
print('- Subtraction')
print('* Multiplication')
print('/ Division')
ch = input('Enter your choice :')
a = float(input('Enter first number :'))
b = float(input('Enter second number :'))
if ch == '+':
result = a+b
print ('Addition :' , result)
elif ch == '-':
result = a-b
print ('Subtraction :' , result)
elif ch == '*':
result = a*b
print ('Multiplication :' , result)
elif ch == '/':
if b == 0:
print ('Division :' , result)
else:
print ('Division by zero is not valid')
else:
print('ERROR = INVALID OPERATOR')

PRESS FOR
+ Addition
- Subtraction
* Multiplication
/ Division
Enter your choice :+
Enter first number :24
Enter second number :21
Addition : 45.0
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\addition, subtraction and multiplication.py
PRESS FOR
+ Addition
- Subtraction
* Multiplication
/ Division
Enter your choice :-
Enter first number :34
Enter second number :53
Subtraction : -19.0
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\addition, subtraction and multiplication.py
PRESS FOR
+ Addition
- Subtraction
* Multiplication
/ Division
Enter your choice :*
Enter first number :236
Enter second number :43
Multiplication : 10148.0
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\addition, subtraction and multiplication.py
PRESS FOR
+ Addition
- Subtraction
* Multiplication
/ Division
Enter your choice :/
Enter first number :0
Enter second number :34
Division by zero is not valid
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\addition, subtraction and multiplication.py
PRESS FOR
+ Addition
- Subtraction
* Multiplication
/ Division
Enter your choice :/
Enter first number :564
Enter second number :64
Division by zero is not valid
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\addition, subtraction and multiplication.py
PRESS FOR
+ Addition
- Subtraction
* Multiplication
/ Division
Enter your choice :%
Enter first number :34
Enter second number :2
ERROR = INVALID OPERATOR
>>>
# even or odd numbers

n = float(input('Enter a number: '))


if n%2 == 0:
print('EVEN NUMBER')
else:
print('ODD NUMBER')

Enter a number: 432


EVEN NUMBER
>>>
= RESTART: C:\Users\user\AppData\Local\Programs\Python\Python39-32\Python\Assignment2 (If
Else)\even or odd numbers.py
Enter a number: 785
ODD NUMBER
>>>

You might also like