Python Program
Python Program
CONVERSION OF TEMPERATURE
PROGRAM
PROGRAM
grade = 'A'
grade = 'B'
grade = 'C'
else:
grade = 'E'
print("\nName: \t", n)
98
89
78
88
80
Name: Arun
RegNo: 12345
Average: 86.6
Percentage: 86.6 %
Grade: A
3. AREA OF RECTANGLE, SQUARE, CIRCLE AND TRIANGLE
PROGRAM
rarea=float(rl*rb)
sarea=float(si*si)
carea=float((3.14)*cr*cr)
tarea=float((0.5)*(tb)*(th))
PROGRAM
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
if num < 0:
elif num == 0:
else:
The factorial of 0 is 1
PROGRAM
n1, n2 = 0, 1
count = 0
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
print("Fibonacci series:")
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
OUTPUT
Fibonacci series:
13
7. COUNT THE NUMBER OF EVEN AND ODD NUMBERS
PROGRAM
even_count, odd_count = 0, 0
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
PROGRAM
class py_solution:
print(py_solution().reverse_words('Hello World'))
OUTPUT
World Hello
9. TO COUNT THE OCCURRENCES OF ALL ITEMS OF THE LIST IN THE TUPLE
PROGRAM
Output: 3
10. CREATE A SAVINGS ACCOUNT CLASS (USING INHERITANCE)
PROGRAM
class BankAccount:
def __init__(self, account_number, balance=0.0):
self.account_number = account_number
self.balance = balance
def display_balance(self):
print(f"Account {self.account_number} Balance: {self.balance}")
class SavingsAccount(BankAccount):
def __init__(self, account_number, balance=0.0, interest_rate=0.0):
super().__init__(account_number, balance)
self.interest_rate = interest_rate # Interest rate as a percentage
def apply_interest(self):
interest = self.balance * (self.interest_rate / 100)
self.balance += interest
print(f"Interest applied at {self.interest_rate}%. New Balance: {self.balance}")
*
**
***
****
*****
****
***
**
*
12. MATRIX MULTIPLICATION
PROGRAM
for i in range(2):
for j in range(2):
result[i][j] = (matrix_a[i][0] * matrix_b[0][j] +
matrix_a[i][1] * matrix_b[1][j])
[19, 22]
[43, 50]
13. PASCAL'S TRIANGLE
PROGRAM
from math import factorial
n=5
for i in range(n):
for j in range(n-i+1):
print(end=" ")
for j in range(i+1):
print(factorial(i)//(factorial(j)*factorial(i-j)), end=" ")
print()
OUTPUT
1
11
121
1331
14641
14. READ A FILE CONTENT AND COPY ONLY THE CONTENTS AT ODD AND
EVEN LINES INTO A SEPARATE FILE
PROGRAM
f=open("sample.txt","r")
line=f.readlines()
evtxt=[]
odtxt=[]
if (i+1)%2==0:
evtxt.append(line)
else:
odtxt.append(line)
for x in evtxt:
print(x,end="")
for x in odtxt:
print(x,end="")
OUTPUT
two
four
six
eight
ten
one
three
five
seven
nine
15.. CREATION OF TURTLE GRAPHICS WINDOW
PROGRAM
import turtle
drawing_area=turtle.Screen()
drawing_area.setup(width=550,height=330)
OUTPUT