0% found this document useful (0 votes)
11 views21 pages

7-14 Python

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

7-14 Python

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

Program:-

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:-

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=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

pi=int(input("Enter the Number of


Pizzas : ")) pi=pi*Pizza
pu=int(input("Enter the Number of
Puffs : ")) pu=pu*Puffs
cd=int(input("Enter the Number of Cool
Drinks : ")) cd=cd*CD

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 : "))

print('''\nEnter the coressponding numbers one by one where the


numbers that correspond to the alphabets are from 65 to 90:-\
n''')

for i in range(0,n,1):
a=int(input("Enter the
number : ")) N=a-65
String=String+Alpha[N]

print("The Final Characters are :- \n",String)


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=Fals
e
break
if
T==Tru
e: 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
brea
k if
t==True:
print("The maximum mark score in ",i+1," semester
is :",max(Marks))
Output:-

You might also like