training day 9
Programs in python
Program for reversed string
s = input("Enter the string : ")
def reverse(s):
s = " " , join(reversed(s))
return s
print("The original string is :")
print(s)
print("The reversed string is :")
print(reverse(s))
Program to reverse a string using classes
class string :
def __init__(self,s):
self.string = s
def reverse(self):
st = " ".join(reversed(self.string))
return st
x = string("Hello")
print(x.reverse())
Program to find area and perimeter of a circle
class circle:
def __init__(self,r):
self.radius = r
def area(self):
print("Area of circle")
print("Area of circle")
Area = 3.14*self.radius*self.radius
return area
def peri(self):
print("Circumference of circle ")
print("Circumference of circle ")
peri = 2*3.14*self.raduis
return peri
x = circle(5)
print(x.area())
print(x.peri())
Comments
Post a Comment