7-14 Python
7-14 Python
def fib(n):
if n<=1:
return n
else:
return(fib(n-1)+fib(n-2))
#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
Output:-
Program:-
a=int(input("Enter the start : "))
b=int(input("Enter the finish : "))
c=len(str(b))
zero=0
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=addition()
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=100
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]
Output:-
Program:-
C=input("Enter the car number plate that you desire : ")
C_N=0
T=True
for j in C:
if int(j) not in [3,5,7]:
print("It is not a lucky number")
T=False
break
if T==True:
for i in C:
C_N=C_N+int(i)
F=""
if (C_N%3==0) or (C_N%5==0) or (C_N%7==0):
print("It is a valid car number")
else:
print("It is not a valid car number.")
Output:-
Program:-
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
break
if t==True:
print("The maximum mark score in ",i+1," semester is :",max(Marks))
Output:-