7-14 Python
7-14 Python
def
fib(n):
if
n<=1:
return
n else:
return(fib(n-1)+fib(n-2))
terms=int(input("Enter no. of
terms: ")) if terms<=0:
print("Input a positive
number!") else:
print("Fibonacci
series: ") for i in
range(0, terms):
print(fib(i), end=" ")
Output:-
Program:-
f=open("Good.txt",
"r") a=f.readlines()
Biggest_line=""
B_l=0
#for biggest
line for i in a:
a=i.split
()
b=len(a
) if
b>B_l:
B_l=b
Biggest_line
=i
#frequency of a
word f.seek(0)
r=f.read
()
r=r.split
() fre=""
frq=0
for j in r:
q=r.count
(j) if
q>frq:
frq=
q
fre=
j
print("Biggest line :
",Biggest_line) print("Most
occuring word : ",fre)
print("Occurance : ",frq)
Text File:-
Output:-
Program:-
for i in
range(a,b,1):
af = str(i)
z=c-
len(af) if
len(af)<c:
print("0"*z,end
=af) print(" ")
else:
print(i)
Output:-
Program:-
class shapes:
def init (self):
self.l = int(input("Enter
length: ")) self.b =
int(input("Enter breadth: "))
class
square(shapes):
def init (self):
print("Square :- ")
shapes. init
(self)
print("Square Area= ", self.l * self.l)
class
rec(shapes):
def init
(self):
print("Rectangle :-
") shapes. init
(self)
print("Rectangle Area= ", self.l * self.b)
sq =
square() rc
= rec()
Output:-
Program:-
class n1:
def init (self):
self.n1=int(input("Enter number
1 : "))
class n2:
def init (self):
self.n2=int(input("Enter number
2 : "))
class
addition(n1,n2):
def init (self):
print("Addition:
- ") n1. init
(self) n2.
init (self)
print("Addition: ",self.n1+self.n2)
class sub(n1,n2):
def init
(self):
print("Subtraction
:- ") n1. init
(self)
n2. init (self)
print("Subtraction: ",self.n1-self.n2)
a=additio
n()
d=sub()
Output:-
Program:-
class hus:
def init (self):
self.hus = input("Enter husband: ")
class wife(hus):
def init
(self): hus.
init (self)
self.wife = input("Enter wife: ")
class child(wife):
def init
(self):
wife. init (self)
self.child = input("Enter child: ")
class
family(child):
def init
(self):
child. init (self)
print("\nFamily Trea")
print("Husband: ",
self.hus) print("Wife: ",
self.wife) print("Child:
", self.child)
f = family()
Output:-
Program:-
Pizza=10
0
Puffs=20
CD=10
t=pi+pu+cd
print("\
nBILL")
print("Pizzas : ",pi,"\nPuffs : ",pu,"\nCool drinks : ",cd)
print("\nTotal Amount : ",t)
Output:-
Program :-
Alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
String=""
n=int(input("Enter the number of characters you want to print : "))
for i in range(0,n,1):
a=int(input("Enter the
number : ")) N=a-65
String=String+Alpha[N]
Marks=[0,0,0,0,0]
for i in range(0,3,1):
print("\nEnter the ",i+1," semester
marks :- ") for j in range(1,6,1):
m=int(input(f"Enter the mark for subject
{j} : ")) if m<=100:
Marks[j-
1]=m
t=True
else:
print("You have entered invalid
Mark") t=False
brea
k if
t==True:
print("The maximum mark score in ",i+1," semester
is :",max(Marks))
Output:-