Skip to content

Commit 567ebc2

Browse files
Add files via upload
1 parent 94e01de commit 567ebc2

24 files changed

+392
-0
lines changed

add.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def add (a,b) :
2+
return a+b
3+
print(add(4,5))

cal.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import add
2+
print(__name__)

factorialfunction.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# program to find factorial of a number
2+
3+
import math
4+
5+
def factorial(n):
6+
return(math.factorial(n))
7+
8+
9+
n = int(input("enter number : "))
10+
print("Factorial :",factorial(n))

file.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with open("sample.txt",'w') as file :
2+
file.write(" 123 ")
3+
4+
s = input("enter file name : ")
5+
name = open(s)
6+
print(name.read())

greater.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# # finding the greatest among the three numbers
2+
3+
4+
# a = [ 3,4,7]
5+
# b = max(a)
6+
# print(b)
7+
8+
9+
10+
def greatest(a,b,c):
11+
if a>b and a>c :
12+
return a
13+
elif b>a and b>c :
14+
return b
15+
else :
16+
return c
17+
18+
a = int(input("enter a : "))
19+
b = int(input("enter b : "))
20+
c = int (input ("enter c : "))
21+
22+
print("greatest number is : ",greatest(a,b,c))

inheritance.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Person(object):
2+
def __init__(self, name):
3+
self.name = name
4+
def get_details(self):
5+
return self.name
6+
class Student(Person):
7+
def __init__(self, name, branch, year):
8+
super().__init__(name)
9+
self.branch = branch
10+
self.year = year
11+
def get_details(self):
12+
return "%s studies %s and is in %s year." % (self.name, self.branch, self.year)
13+
class Teacher(Person):
14+
def __init__(self, name, papers):
15+
super().__init__(name)
16+
self.papers = papers
17+
def get_details(self):
18+
return "%s teaches %s" % (self.name, ','.join(self.papers))
19+
person1 = Person('rahul')
20+
student1 = Student('RAHUL', 'IT', 2027)
21+
teacher1 = Teacher('dimple', ['python'])
22+
print(person1.get_details())
23+
print(student1.get_details())
24+
print(teacher1.get_details())

init.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Student(object):
2+
def __init__(self, name, branch, year):
3+
self.name = name
4+
self.branch = branch
5+
self.year = year
6+
print("A student object is created.")
7+
def print_details(self):
8+
print("Name:", self.name)
9+
print("Branch:", self.branch)
10+
print("Year:", self.year)
11+
a = Student('rahul' , ' it' , ' 2027')
12+
a.print_details()
13+

logo.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import tensorflow as tf
2+
from tensorflow.keras import datasets, layers, models
3+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
4+
import matplotlib.pyplot as plt
5+
6+
# Load dataset - here we're assuming the dataset is already prepared and split into folders (train, test)
7+
train_dir = "path_to_train_data"
8+
test_dir = "path_to_test_data"
9+
10+
# Image augmentation for data preprocessing
11+
train_datagen = ImageDataGenerator(
12+
rescale=1./255,
13+
rotation_range=20,
14+
width_shift_range=0.2,
15+
height_shift_range=0.2,
16+
shear_range=0.2,
17+
zoom_range=0.2,
18+
horizontal_flip=True,
19+
fill_mode='nearest'
20+
)
21+
22+
test_datagen = ImageDataGenerator(rescale=1./255)
23+
24+
train_generator = train_datagen.flow_from_directory(
25+
train_dir,
26+
target_size=(224, 224),
27+
batch_size=32,
28+
class_mode='binary' # Since it's fake vs genuine logo classification
29+
)
30+
31+
test_generator = test_datagen.flow_from_directory(
32+
test_dir,
33+
target_size=(224, 224),
34+
batch_size=32,
35+
class_mode='binary'
36+
)
37+
38+
# Build a CNN model (simple version)
39+
model = models.Sequential([
40+
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),
41+
layers.MaxPooling2D((2, 2)),
42+
layers.Conv2D(64, (3, 3), activation='relu'),
43+
layers.MaxPooling2D((2, 2)),
44+
layers.Conv2D(128, (3, 3), activation='relu'),
45+
layers.MaxPooling2D((2, 2)),
46+
layers.Flatten(),
47+
layers.Dense(512, activation='relu'),
48+
layers.Dense(1, activation='sigmoid') # Binary classification (fake vs genuine)
49+
])
50+
51+
# Compile the model
52+
model.compile(optimizer='adam',
53+
loss='binary_crossentropy',
54+
metrics=['accuracy'])
55+
56+
# Train the model
57+
history = model.fit(train_generator,
58+
steps_per_epoch=100,
59+
epochs=10,
60+
validation_data=test_generator,
61+
validation_steps=50)
62+
63+
# Plot training & validation accuracy and loss
64+
plt.plot(history.history['accuracy'], label='train accuracy')
65+
plt.plot(history.history['val_accuracy'], label='val accuracy')
66+
plt.legend()
67+
plt.show()
68+
69+
plt.plot(history.history['loss'], label='train loss')
70+
plt.plot(history.history['val_loss'], label='val loss')
71+
plt.legend()
72+
plt.show()
73+
74+
# Evaluate the model
75+
test_loss, test_acc = model.evaluate(test_generator, steps=50)
76+
print(f'Test accuracy: {test_acc}')

mergec.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file1 = file2 = file3 = ""
2+
with open("files/file1") as file1 :
3+
data = file1.readlines()
4+
with open("files/file1") as file1 :
5+
data = file1.readlines()

multiinherit.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class calculation1 () :
2+
def sum(self,a,b):
3+
return a+b;
4+
class calculation2 () :
5+
def multiply(self , a, b ) :
6+
return a*b ;
7+
class derived(calculation1 , calculation2 ):
8+
def divide(self, a, b ):
9+
return a/b;
10+
d= derived()
11+
print(d.sum(10,20))
12+
print(d.multiply(2,3))
13+
print(d.divide(4,2))

mutlilevel.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class parent () :
2+
def speak(self) :
3+
print(" parents are speaking" )
4+
class child (parent):
5+
def walk(self) :
6+
print("child is walking ")
7+
class smallchild(child) :
8+
def eat (self) :
9+
print("small child is eating ")
10+
a = smallchild()
11+
a.speak()
12+
a.walk()
13+
a.eat()

overloading.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Human:
2+
def sayHello (self, name= None ):
3+
if name is not None :
4+
print('Hello' + name )
5+
else :
6+
print ("Hello " )
7+
a = Human ()
8+
print(a.sayHello())
9+
print(a.sayHello('rahul'))
10+

overriding.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class school:
2+
def getstd(self):
3+
return 12 ;
4+
class rps (school):
5+
def getstd(self):
6+
return 7;
7+
class oxford(school):
8+
def getstd(self):
9+
return 8 ;
10+
a = school()
11+
b = rps()
12+
c = oxford()
13+
print("no. of student in school ",a.getstd());
14+
print("no. of student in rps " , b.getstd());
15+
print(" no. of student in oxford " , c.getstd());

perimeter.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# perimeter of a rectangle
2+
3+
def perimeter(a,b):
4+
return 4*(a+b)
5+
a = int(input("enter length : "))
6+
b = int(input("enter width : "))
7+
8+
print(perimeter(a,b))

power.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# power function
2+
3+
def power(b,e):
4+
return pow(b,e)
5+
b = int(input("enter base : "))
6+
e = int(input("enter exponential power : "))
7+
8+
print(power(b,e))

primefactorization.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# to find factors of a number
2+
3+
import math
4+
5+
6+
def factors(n):
7+
8+
9+
while n % 2 == 0:
10+
print(2)
11+
n = n // 2
12+
13+
14+
for i in range(3,int(math.sqrt(n))+1):
15+
16+
while n % i== 0:
17+
print(i)
18+
n = n // i
19+
20+
21+
if n > 2:
22+
print(n)
23+
24+
25+
n = int(input("enter number: "))
26+
factors(n)
27+
28+

private.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class obj:
2+
__name = None
3+
__roll = None
4+
__branch = None
5+
def __init__(self, name, roll, branch):
6+
self.__name = name
7+
self.__roll = roll
8+
self.__branch = branch
9+
def __displayDetails(self):
10+
print("Name:", self.__name)
11+
print("Roll:", self.__roll)
12+
print("Branch:", self.__branch)
13+
def accessPrivateFunction(self):
14+
self.__displayDetails()
15+
a = obj("Rahul", 23001011049, "Information Technology")
16+
print(a._obj__name)
17+
print(a._obj__roll)
18+
print(a._obj__branch)
19+
a.accessPrivateFunction()
20+

project.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import tkinter as tk
2+
from tkinter import messagebox
3+
import pyshorteners
4+
5+
def shorten_link():
6+
original_url = entry.get()
7+
if not original_url:
8+
messagebox.showerror("Error", "Please enter a URL to shorten.")
9+
return
10+
11+
try:
12+
s = pyshorteners.Shortener()
13+
shortened_url = s.tinyurl.short(original_url)
14+
shortened_label.config(text=f"Shortened URL: {shortened_url}")
15+
copy_button.config(state=tk.NORMAL)
16+
except Exception as e:
17+
messagebox.showerror("Error", f"An error occurred: {e}")
18+
19+
def copy_to_clipboard():
20+
shortened_url = shortened_label.cget("text").split(": ")[1]
21+
root.clipboard_clear()
22+
root.clipboard_append(shortened_url)
23+
messagebox.showinfo("Success", "Shortened URL copied to clipboard!")
24+
root = tk.Tk()
25+
root.title("Link Shortener")
26+
label = tk.Label(root, text="Enter URL:")
27+
label.pack()
28+
entry = tk.Entry(root)
29+
entry.pack()
30+
shorten_button = tk.Button(root, text="Shorten", command=shorten_link)
31+
shorten_button.pack()
32+
shortened_label = tk.Label(root, text="")
33+
shortened_label.pack()
34+
copy_button = tk.Button(root, text="Copy Shortened URL", command=copy_to_clipboard, state=tk.DISABLED)
35+
copy_button.pack()
36+
root.mainloop()

protect.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Student:
2+
_name = None
3+
_roll = None
4+
_branch = None
5+
def __init__(self, name, roll, branch):
6+
self._name = name
7+
self._roll = roll
8+
self._branch = branch
9+
def _displayRollAndBranch(self):
10+
print("Roll:", self._roll)
11+
print("Branch:", self._branch)
12+
class obj(Student):
13+
def __init__(self, name, roll, branch):
14+
Student.__init__(self, name, roll, branch)
15+
def displayDetails(self):
16+
print("Name:", self._name)
17+
self._displayRollAndBranch()
18+
stu = Student("keshav", 2300101105, "Computer Science")
19+
print(stu._name)
20+
stu._displayRollAndBranch()
21+
a= obj("Rahul", 23001011049, "Information Technology")
22+
a.displayDetails()
23+

public.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class obj:
2+
def __init__(self, name, age):
3+
self.objName = name
4+
self.objAge = age
5+
def displayAge(self):
6+
print("Age: ", self.objAge)
7+
a = obj("Rahul", 20)
8+
print("Name:", a.objName)
9+
a.displayAge()
10+

rectanglec.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# area of rectangle using different length or width
2+
def area (a , b ):
3+
return a*b
4+
a = int(input("enter length : "))
5+
b = int(input("enter width : "))
6+
print(area(a,b))
7+
8+
9+
# fixed input
10+
11+
def area(a,b):
12+
return a*b
13+
print(area(3,4))
14+
15+

0 commit comments

Comments
 (0)