python programs on unit 1
python programs on unit 1
b= int(input("enter a breath="))
area=l*b
print("area of rectangle=",area)
i =u*74.79
print("indian rupees", i)
s=int(input("enter side="))
print("area=",s*s)
print("perimeter=",4*s)
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)
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
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 = 1
for i in range(1,11):
sum=i+sum
print(sum)
8) Write a python program for fibonacci series
n1=0
n2=1
next=n1+n2
if last>1:
print(n1)
print(n2)
while next<=last:
print (next)
n1=n2
n2=next
next=n1+n2
else:
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
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)
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
rev=0
n1=n
print("original number=",n)
while n!=0:
digit=int(n%10)
n=int(n/10)
rev=int(rev*10+digit)
if n1==rev:
print("palindrome no.")
else:
13)write a python program which print the following pattern using loop
**
***
****
for r in range(0,4):
print("\r")
for c in range(0,r+1):
print("*",end=" ")
programs on conditional statements
if (x%2==0):
else:
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
17) write a program to check if the input year is a leap year or not
if(x%4==0):
if(x%400==0):
if (x%100!=0):
else:
else:
else:
if(x>0):
print("number is positive")
if(x<0):
print("number is negative")
if(x==0):
print("number is zero")