PythonFile_Divyansh_24070
PythonFile_Divyansh_24070
FUNDAMENTALS
[AY 2024-25]
PRACTICAL FILE
Submitted by –
Divyansh
BMS 1 C
24070
3
INDEX
4
5
6
PROGRAM 1.1
print("Hello world")
PROGRAM 1.2
a = 50
b = 10
PROGRAM 2.1
p = int(input("Enter the principle amount: "))
def simpleinterest(p,r,t):
SI = p + (p*r*t)/100
return SI
def compoundedinterest(p,r,t):
CI = p*(1+r/100)**t
return CI
7
PROGRAM 2.2
a = input("Enter the shape whose area you want to calculate (Circle/Square/Rectangle): ")
if a == "Circle":
area_r= 3.14*r*r
elif a == "Square":
area_s = s**2
elif a == "Rectangle":
area_r = s2*s3
else:
print("Invalid Input")
PROGRAM 3.1
a = int(input("Enter the number: "))
print(a,"X",i,"=",a*i)
8
PROGRAM 3.2
a = int(input("Enter the left value of the range: "))
odd = 0
if i%2 != 0:
odd += 1
PROGRAM 3.3
a = int(input("Enter the left value of the range: "))
even = 0
if i%2 == 0:
even += 1
PROGRAM 3.4
a = int(input("Enter the number: "))
print(a,"^",i,"=",a**i)
9
PROGRAM 4.1
a = int(input("Enter the number: "))
if a%5 == 0:
else:
PROGRAM 4.2
a = int(input("Enter the year you want to check: "))
else:
PROGRAM 4.3
a = int(input("Enter your score: "))
if a >= 90:
elif a>=60:
elif a>=40:
else:
10
PROGRAM 5.1
a = int(input("Enter the weight of your baggage: "))
b = a - 20
if b<=0:
elif b <=10:
elif b <=20:
elif b >20:
PROGRAM 6.1
a = int(input("Enter the number: "))
i=0
while i<=10:
print(a,"X",i,"=",a*i)
i += 1
PROGRAM 6.2
a = int(input("Enter the value of n: "))
i=0
sum = 0
while i<=a:
sum += i
i += 1
11
PROGRAM 6.3
a = ''
b = "12345"
while a != b:
if a != b:
print("Wrong password")
else:
print("Correct Password")
PROGRAM 7.1
multiple = 0
i=0
while i <=a:
if i%5 ==0:
multiple +=1
i+= 1
PROGRAM 8.1
def matrix_multiplication(A, B):
12
if cols_A != rows_B:
for i in range(rows_A):
for j in range(cols_B):
for k in range(cols_A):
return result
A = [[1, 2, 3],
[4, 5, 6]]
B = [[7, 8],
[9, 10],
[11, 12]]
result = matrix_multiplication(A, B)
print(row)
PROGRAM 9.1
i=0
while i <6:
i+= 1
13
PROGRAM 9.2
a = []
c = list(map(int,b.split()))
a.extend(c)
count = 0
for i in a:
if i< 18:
count += 1
PROGRAM 9.3
a = []
c = list(map(int,b.split()))
a.extend(c)
count = 0
sum = 0
for i in a:
sum += i
i+= 1
14
PROGRAM 10.1
lst_1 = [1,2,3,4,5]
lst_2 = [5,4,2,9,10]
a = set(lst_1)
b = set(lst_2)
lst_3 = list(a.symmetric_difference(b))
PROGRAM 10.2
s = {1,2,3,4,5,8,9,10}
a = max(s)
b = min(s)
PROGRAM 10.3
l = [1,2,3,4,5,1,1]
a = list(set(l))
15
PROGRAM 10.4
s1 = {1,2,3,4}
s2 = {5,6,7,8}
PROGRAM 10.5
def power_set(input_set):
result = [[]]
return result
input_set = [1, 2, 3]
print(power_set(input_set))
PROGRAM 10.6
dic = {'a':1,'b':2,'d':3,'c':4}
sort1 = dict(sorted(dic.items()))
print(sort1)
print(sort2)
PROGRAM 11.1
l = ["Aditya","Aman","Raj","Aditya","Aman","Vanya","Bihar"]
count = {}
16
for i in l:
if i in count:
count[i] += 1
else:
count[i] = 1
print(count)
PROGRAM 11.2
d = {'a':1,'b':2,'c':3,'d':4}
c = max(d.keys())
PROGRAM 11.3
a = [1,2,3,4]
b = [5,6,7,8]
c = dict(zip(a,b))
print(c)
PROGRAM 11.4
def reverse_sentence(sentence):
words = sentence.split()
reversed_words = words[::-1]
17
sentence = "Hello world this is Python"
print(reverse_sentence(sentence))
PROGRAM 11.5
def reverse_list(lst):
return lst[::-1]
print(reverse_list([1, 2, 3, 4]))
PROGRAM 11.6
def sort_list(lst):
return sorted(lst)
# Example usage
print(sort_list([4, 1, 3, 2]))
PROGRAM 12.1
def find_index(lst, target):
PROGRAM 12.2
def to_uppercase(string):
return string.upper()
print(to_uppercase("hello"))
18
PROGRAM 12.3
def remove_duplicates(lst):
return list(set(lst))
print(remove_duplicates([1, 2, 2, 3, 3, 3]))
PROGRAM 12.4
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
print(factorial(5))
PROGRAM 12.5
def add_a_to_itself(a, b):
return a * b
print(add_a_to_itself(3, 4))
PROGRAM 12.6
def sum_args(*args):
return sum(args)
print(sum_args(1, 2, 3, 4))
PROGRAM 12.7
def full_name(first, last):
print(full_name("John", "Doe"))
19
PROGRAM 12.8
import math
def area_of_circle(radius):
print(area_of_circle(5))
PROGRAM 13.1
class Interest:
self.principal = principal
self.rate = rate
self.time = time
def simple_interest(self):
def compound_interest(self):
interest = Interest(1000, 5, 2)
print(interest.simple_interest())
print(interest.compound_interest())
PROGRAM 13.2
class Rectangle:
self.length = length
self.width = width
20
def area(self):
rect = Rectangle(5, 4)
print(rect.area())
PROGRAM 14.1
def is_prime(num):
if num <= 1:
return False
if num % i == 0:
return False
return True
print(is_prime(7))
PROGRAM 14.2
def max_of_three(a, b, c):
return max(a, b, c)
PROGRAM 15.1
def area_of_rectangle(length, width):
import rectangle_module
print(rectangle_module.area_of_rectangle(5, 4))
21
PROGRAM 15.2
from datetime import datetime
print(record_transaction(100, "Deposit"))
PROGRAM 16.1
class AddNumbers:
self.num1 = num1
self.num2 = num2
def add(self):
adder = AddNumbers(5, 3)
print(adder.add())
PROGRAM 17.1
import numpy as np
def positive_elements(arr):
print(positive_elements(array))
22
PROGRAM 18.1
import matplotlib.pyplot as plt
plt.bar(x, y)
plt.show()
PROGRAM 18.2
import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show()
PROGRAM 18.3
import matplotlib.pyplot as plt
plt.show()
23
PROGRAM 18.4
import matplotlib.pyplot as plt
plt.hist(data, bins=bins)
plt.show()
PROGRAM 18.5
import matplotlib.pyplot as plt
plt.scatter(x, y)
plt.show()
PROGRAM 19.1
import pandas as pd
def read_csv(file_path):
return pd.read_csv(file_path)
df = read_csv('file.csv')
print(df)
PROGRAM 19.2
def overwrite_file(file_path, content):
file.write(content)
24
PROGRAM 19.3
def filter_lines(file_path):
lines = file.readlines()
filtered = filter_lines('example.txt')
print(filtered)
PROGRAM 20.1
import pandas as pd
def create_and_multiply(series_data):
series = pd.Series(series_data)
return series * 2
print(create_and_multiply([1, 2, 3]))
PROGRAM 20.2
import pandas as pd
s1 = pd.Series([1, 2, 3])
s2 = pd.Series([4, 5, 6])
print(series_operations(s1, s2))
PROGRAM 20.3
import pandas as pd
25
data = [[1, 'Alice'], [2, 'Bob']]
print(create_dataframe(data, columns))
PROGRAM 20.4
import pandas as pd
def read_dataframe(file_path):
return pd.read_csv(file_path)
df = read_dataframe('file.csv')
print(df)
PROGRAM 20.5
import pandas as pd
print(combine_dataframes(df1, df2))
PROGRAM 20.6
import pandas as pd
26
PROGRAM 20.7
import pandas as pd
print(combine_common_rows(df1, df2))
PROGRAM 20.8
import pandas as pd
PROGRAM 20.9
import pandas as pd
return merged
27
print(rename_columns_outer_join(df1, df2))
PROGRAM 20.10
import pandas as pd
PROGRAM 21.1
import pandas as pd
def dataframe_operations():
df = pd.DataFrame(data)
max_score = df['Score'].max()
min_score = df['Score'].min()
mean_score = df['Score'].mean()
print(dataframe_operations())
28
PROGRAM 22.1
def is_palindrome(string):
print(is_palindrome("madam"))
print(is_palindrome("hello"))
PROGRAM 22.2
primes = []
if num > 1:
if num % i == 0:
break
else:
primes.append(num)
return primes
print(primes_in_range(10, 20))
29