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

python programs on unit 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

python programs on unit 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Python Programs on unit 1

1) Write a program to find the area of rectangle

#program to find the area of rectangle

l=int (input("enter a length"))

b= int(input("enter a breath="))

area=l*b

print("area of rectangle=",area)

2) Write a python program to convert US dollar into indian ruppes

#program to convert US dollar into indian ruppes

print("us dollar to indian rupees $1= rs.74.79")

u=int(input("enter U.S.dollar amount="))

i =u*74.79

print("indian rupees", i)

3) Write a program to calculate area and perimeter of the square

#program to calculate area and perimeter of the square

print("calculate area and perimeter of square")

s=int(input("enter side="))

print("area=",s*s)

print("perimeter=",4*s)

4) Write a program to calculate surface volume and area of cylinder

#Program to calculate surface volume and area of cylinder

pi=3.14

r=int(input('enter a radias='))

h=int(input('enter a height='))

v=pi*(r*r)

print('volume of cylinder=',v)

a=2*pi*r*h+2*v
print ('area of cylinder=',a)

5) Write a python program to swap the value of two variables

# program to swap the value of two variables

n1=int(input('enter a 1st no.='))

n2=int(input('enter a 2nd no.='))

temp=n1

n1=n2

n2=temp

print('1st no=',n1)

print('2nd no.=',n2)

program on loops

6) Write a python program printing all even number between 1 to 100 using while loop

#printing even number upto100

x=1

while x<=100:

if (x%2==0):

print("it is even:",x)

x+=1

7) Write a python program to calculate the sum of first 10 natural no. using for loop

# sum of first 10 natural no. using for loop

sum = 1

for i in range(1,11):

sum=i+sum

print(sum)
8) Write a python program for fibonacci series

#program for fibonacci series

last=int(input ("enter last term="))

n1=0

n2=1

next=n1+n2

if last>1:

print(n1)

print(n2)

print("fibonnaci series from 0 to",last)

while next<=last:

print (next)

n1=n2

n2=next

next=n1+n2

else:

print("please enter value greter than 1")

9) Write a python program for factorial of given no.

#program for factorial of given no.

n=int(input("enter number to find factorial="))

f=1

print("factorial of :",n)

while n>=1:

f=f*n

n=n-1

print(f)
10) write a python program which takes in a number and find the sum of digit in a number

#program takes in a number and find the sum of digit in a number

n=int(input("enter a number="))

sum=0

print("original number=",n)

while n!=0:

digit=int(n%10)

n=int(n/10)

sum=int(sum+digit)

print("sum=",sum)

11) write a python program for reverse the given no.

#program for reverse the given no.

n=int(input("enter number="))

rev=0

print("original number=",n)

while n!=0:

digit=int(n%10)

n=int(n/10)

rev=int(rev*10+digit)

print("reverse number=",rev)
12)write a python program which takes a number and checks whether it is a palindrome or
not

# program takes a number and checks whether it is a palindrome or not

n=int (input("enter number="))

rev=0

n1=n

print("original number=",n)

while n!=0:

digit=int(n%10)

n=int(n/10)

rev=int(rev*10+digit)

print("reversed no. =",rev)

if n1==rev:

print("palindrome no.")

else:

print("not a palindrome no.")

13)write a python program which print the following pattern using loop

**

***

****

#print pattern using loop

for r in range(0,4):

print("\r")

for c in range(0,r+1):

print("*",end=" ")
programs on conditional statements

14) write a program to check wheather the no. is even or odd

#write a program to check wheather the no. is even or odd

print("number is even or odd check")

x= int (input("enter the value of x:"))

if (x%2==0):

print("it is even number")

else:

print("it is odd number")

15) write a program to find out absolute value of an input number

#write a program to find out absolute value of an input number

x=int (input("enter the value of x:="))

if (x<0):

x=(-1)*x

print("absolute number",x)

16) write a program to check the largest number among the three number

#write a program to check the largest number among the three number

x=int(input("enter the 1st no.:="))

y=int(input("enter the 2nd no.:="))

z=int(input("enter the 3rd no.:="))

if(x>y and x>z):

print(" 1st number is greater := ",x)

elif (y>x and y>z):

print("2nd number is greater:=",y)

elif(z>x and z>y):


print ("3rd no. is greaterL:=",z)

17) write a program to check if the input year is a leap year or not

#write a program to check if the input year is a leap year or not

x=int(input("enter the value of year.:="))

if(x%4==0):

if(x%400==0):

if (x%100!=0):

print("this is leap year:",x)

else:

print("it is not a leap year")

else:

print("this is leap year")

else:

print("it is not a leap year")

18) write a program to check if a number is positive ,negative, or zero

#write a program to check if a number is positive ,negative, or zero

x=int(input("enter the value of x:="))

if(x>0):

print("number is positive")

if(x<0):

print("number is negative")

if(x==0):

print("number is zero")

You might also like