IP11B

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

PROGRAM- 1

1.Write a python program to enter a number and display if the given number is
even or odd.

SOURCE CODE:
n=int(input("Enter the number:"))
if n%2==0:
print("The number is even")
else:
print("The number is odd”)

OUTPUT:

Enter the number: 4


The number is even

Enter the number: 3


The number is odd
PROGRAM-2
2. Write a Python program to check if a number entered is positive, negative or
zero.

SOURCE CODE:
n=int(input("Enter the number:"))
if n<0:
print("The number is negative")
elif n>0:
print("The number is positive")
else:
print("The number is zero”)

OUTPUT:

Enter the number: 3


The number is positive

Enter the number: -5


The number is negative
PROGRAM-3

3) Write a Python program to enter three numbers and find the largest number.

SOURCE CODE:
a=int(input('Enter the first number:'))
b=int(input('Enter the second number:'))
c=int(input('Enter the third number:'))
if a>b:
if a>c:
print(a,'is the largest number:')
else:
print(c,'is the largest number')
if b>c:
print(b,'is the largest number')
else:
print(c,'is the largest number')

OUTPUT:
Enter the first number:11
Enter the second number:9
Enter the third number:15
15 is the largest number
PROGRAM-4
4) Write a program in Python to find the grade based on the marks entered:

SOURCE CODE:
a=int(input('Enter marks of the first subject'))
b=int(input('Enter marks of the second subject'))
c=int(input('Enter marks of the third subject'))
d=int(input('Enter marks of the fourth subject'))
e=int(input('Enter the marks of the fifth subject'))
avg=(a+b+c+d+e)/5
while True:
if avg>=80:
print('Grade is distinction')
elif avg>=65 and avg<80:
print('Grade is first class')
elif avg>=45 and avg<65:
print('Grade is second class')
elif avg>=33 and avg<45:
print('Grade is third class')
else:
print('Failed')
break

OUTPUT:
Enter marks of the first subject45
Enter marks of the second subject50
Enter marks of the third subject60
Enter marks of the fourth subject55
Enter the marks of the fifth subject40
Grade is second class
PROGRAM-5
5) WAP to display first n multiples of a given number

SOURCE CODE:
n=int(input("Enter the number:"))
n1=int(input("Enter no of multiples:"))
for i in range(1,n1+1):
print(i*n)

OUTPUT:
Enter the number:5
Enter no of multiples:6
5
10
15
20
25
30
PROGRAM-6
6) Write a Python program to display the multiplication table of a given number

SOURCE CODE:
n=int(input('Enter the number:'))
n1=int(input('Enter the number of multiples:'))
for i in range(1,n1+1):
print(i,'*',n,'=',i*n)

OUTPUT:
Enter the number:10
Enter the number of multiples:5
1 * 10 = 10
2 * 10 = 20
3 * 10 = 30
4 * 10 = 40
5 * 10 = 50
PROGRAM-7
7) Write a Python program to display the final sum of even numbers.

SOURCE CODE:
n=int(input('Enter the number:'))
s=0
for i in range(1,n+1):
if i%2==0:
s=s+i
print(s)

OUTPUT:
Enter the number:14
56
PROGRAM-8
8) WAP to find the factorial of a given number.

SOURCE CODE;
n=int(input('Enter the number:'))
i=1
prod=1
while i<=n:
prod=prod*i
i=i+1
print(prod)

OUTPUT:
Enter the number:10
3628800
PROGRAM-9
9) WAP to accept name, basic salary, HRA, TA and to calculate the net salary.

SOURCE CODE:
n=input('Enter the name:')
bs=int(input('Enter the basic salary:'))
hr=int(input('Enter HRA:'))
ta=int(input('Enter TA:'))
ns=bs+hr+ta
print('The net salary is',ns)

OUTPUT:
Enter the name: Mahesh
Enter the basic salary:30000
Enter HRA:40
Enter TA:50
The net salary is 30090
PROGRAM-10
10) Write a menu driven program that calculates the following:
i. Area of a circle ii. Circumference of a circle
iii. Area of a rectangle iv. Perimeter of a rectangle

SOURCE CODE:
while True:
print('Menu driven program')
print('1.Area of cicle')
print('2.Circumference of a circle')
print('3.Area of a rectangle')
print('4.Perimeter of a rectangle')
print('5.Exit')
print('--------------------------')
print()
ch=eval(input('Enter your choice:'))
if ch==1:
r=int(input('Enter the radius:'))
x=3.14*r**2
print('Area of the circle is:',x)
print('---------------------------')
print()
elif ch==2:
r=int(input('Enter the radius:'))
x=2*3.14*r
print('Circumference of circle is:'.x)
print('----------------------------')
print()
elif ch==3:
l=int(input('Enter the length:'))
b=int(input('Enter the breadth:'))
x=l*b
print('The are of rectangle is:',x)
print('--------------------------')
print()
elif ch==4:
l=int(input('Enter the length:'))
b=int(input('Enter the breadth:'))
x=2*(l+b)
print('The perimeter of rectangle is:',x)
print('----------------------------')
print()
elif ch==5:
print('Exit’)
break

OUTPUT:
Menu driven program
1.Area of circle
2.Circumference of a circle
3.Area of a rectangle
4.Perimeter of a rectangle
5.Exit
--------------------------

Enter your choice:3


Enter the length:5
Enter the breadth:2
The are of rectangle is: 10

You might also like