Skip to content

Commit 872a691

Browse files
authored
Add files via upload
1 parent aea065d commit 872a691

21 files changed

+718
-0
lines changed

1.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
class Node:
2+
def__init_(self,val):
3+
self.val = val
4+
self.left = left
5+
self.right = None
6+
7+
def bfs(root):
8+
if rootisnone:
9+
return
10+
visited []
11+
queue = [root]
12+
whilequeue:
13+
14+
node = queue.pop(0)
15+
visited.append(node.val)
16+
17+
ifnode.left:
18+
queue.append(node.left)
19+
ifnode.right:
20+
queue.append(node.right)
21+
22+
returnvisited
23+
24+
# example binary tree
25+
# 1
26+
# / \
27+
# 2 3
28+
# / \ / \
29+
# 4 5 6 7
30+
root = Node(1)
31+
root.left = Node(2)
32+
root.right = Node(3)
33+
root.left.left = Node(4)
34+
root.left.right = Node(5)
35+
root.right.left = Node(6)
36+
root.right.right = Node(7)
37+
38+
print(bfs(root)) # Output: [1, 2, 3, 4, 5, 6, 7]
39+
40+
41+
42+
# def__init__(self, val):
43+
# self.val = val
44+
# self.left = None
45+
# self.right = None
46+
47+
# defbfs(root):
48+
# ifrootisNone:
49+
# return
50+
51+
# visited = []
52+
# queue = [root]
53+
54+
# whilequeue:
55+
# node = queue.pop(0)
56+
# visited.append(node.val)
57+
58+
# ifnode.left:
59+
# queue.append(node.left)
60+
# ifnode.right:
61+
# queue.append(node.right)
62+
63+
# returnvisited
64+
65+
# # example binary tree
66+
# # 1
67+
# # / \
68+
# # 2 3
69+
# # / \ / \
70+
# # 4 5 6 7
71+
# root = Node(1)
72+
# root.left = Node(2)
73+
# root.right = Node(3)
74+
# root.left.left = Node(4)
75+
# root.left.right = Node(5)
76+
# root.right.left = Node(6)
77+
# root.right.right = Node(7)
78+
79+
# print(bfs(root)) # Output: [1, 2, 3, 4, 5, 6, 7]

10fact.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# WAP to calculate factorial of a number.
2+
3+
num = int(input("Enter a number: ")) #Get user from input
4+
5+
# Initialize the factorial to 1
6+
factorial = 1
7+
8+
for i in range(1, num + 1): #Using for loop
9+
factorial *= i
10+
11+
print("Factorial of", num, "is", factorial)

11oop.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# WAP to store student info using class (OOP)
2+
3+
# Creating student class
4+
class student:
5+
6+
# constructor for passing student info
7+
def __init__(self,name,rollno,adno,marks):
8+
self.name = name
9+
self.rollno = rollno
10+
self.adno = adno
11+
self.marks = marks
12+
13+
# method to print details
14+
def printDetail(self):
15+
print(f"Name : {self.name}\nRoll no. : {self.rollno}\nAdmission no. : {self.adno}\nMarks : {self.marks}\n")
16+
17+
Std1 = student("Lakshay",17536,"2117536",(96,95,92,89))
18+
Std1.printDetail()
19+
Std2 = student("Suraj",17536,"2117510",(88,98,90,92))
20+
Std2.printDetail()
21+
Std3 = student("Priyanshu",17524,"2117524",(98,82,95,91))
22+
Std3.printDetail()

1area.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Program for Calculating the area of a Circle, Rectangle and Square
2+
3+
# 1. Area of Circle
4+
def circle():
5+
radius = float(input("\nEnter the Radius of Circle : "))
6+
return 3.14*radius*radius
7+
8+
# 2. Area of Square
9+
def square():
10+
side = float(input("\nEnter the Side of Square : "))
11+
return side*side
12+
13+
# Area of Rectangle
14+
def rectangle():
15+
length = float(input("\nEnter the Length of Rectangle : "))
16+
breath = float(input("Enter the Breath of Rectangle : "))
17+
return length*breath
18+
19+
while(True):
20+
print("\nChoose shape for area calculation :")
21+
print("1. Circle\n2. Rectangle\n3. Square\n4. Exit(Any Key)")
22+
choice = input("Enter your choice : ")
23+
if(choice=='1'):
24+
result = circle()
25+
elif(choice=='2'):
26+
result = rectangle()
27+
elif(choice=='3'):
28+
result = square()
29+
else:
30+
print("Exit")
31+
exit()
32+
print("Area of shape is",result)
33+

2.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
2+
Type "help", "copyright", "credits" or "license()" for more information.
3+
>>>
4+
... classNode:
5+
... def__init__(self, val):
6+
... self.val = val
7+
... self.left = None
8+
... self.right = None
9+
...
10+
... defbfs(root):
11+
... ifrootisNone:
12+
... return
13+
...
14+
... visited = []
15+
... queue = [root]
16+
...
17+
... whilequeue:
18+
... node = queue.pop(0)
19+
... visited.append(node.val)
20+
...
21+
... ifnode.left:
22+
... queue.append(node.left)
23+
... ifnode.right:
24+
... queue.append(node.right)
25+
...
26+
... returnvisited
27+
...
28+
... # example binary tree
29+
... # 1
30+
... # / \
31+
... # 2 3
32+
... # / \ / \
33+
... # 4 5 6 7
34+
... root = Node(1)
35+
... root.left = Node(2)
36+
... root.right = Node(3)
37+
... root.left.left = Node(4)
38+
... root.left.right = Node(5)
39+
... root.right.left = Node(6)
40+
... root.right.right = Node(7)
41+
...
42+
... print(bfs(root)) # Output: [1, 2, 3, 4, 5, 6, 7]

2fibo.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Program to display the Fibonacci series
2+
3+
n = int(input(" Enter the number of terms : "))
4+
5+
n1, n2 = 0, 1
6+
count = 0
7+
8+
if n <= 0: # Checking if the number of terms are valid
9+
print("Please enter a valid number")
10+
11+
elif n == 1:
12+
print("Fibonacci sequence upto",n,":")
13+
print(n1)
14+
15+
else:
16+
print("Fibonacci sequence:") # Generating fibonacci sequence
17+
while count < n:
18+
print(n1)
19+
nth = n1 + n2
20+
# Updating values
21+
n1 = n2
22+
n2 = nth
23+
count += 1

3LcmHcf.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def HCF(x, y):
2+
if x > y:
3+
smaller = y
4+
else:
5+
smaller = x
6+
for i in range(1, smaller+1):
7+
if((x % i == 0) and (y % i == 0)):
8+
HCF = i
9+
return HCF
10+
11+
def LCM(x, y):
12+
if x > y:
13+
greater = x
14+
else:
15+
greater = y
16+
while(True):
17+
if((greater % x == 0) and (greater % y == 0)):
18+
LCM = greater
19+
break
20+
greater += 1
21+
return LCM
22+
23+
x = int(input("Enter first number: "))
24+
y = int(input("Enter second number: "))
25+
print("The H.C.F. of", x,"and", y,"is", HCF(x, y))
26+
print("The L.C.M. of", x,"and", y,"is", LCM(x, y))

4mathFunc.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# WAP to illustrate various functions of Statistics module
2+
3+
import statistics
4+
5+
# Create a list of numbers
6+
numbers = [2, 3, 4, 5, 6, 7, 8, 9]
7+
8+
# Printing mean
9+
mean = statistics.mean(numbers)
10+
print("Mean: {}".format(mean))
11+
12+
# Printing the median
13+
median = statistics.median(numbers)
14+
print("Median: {}".format(median))
15+
16+
# Printing the mode (if it exists)
17+
try:
18+
mode = statistics.mode(numbers)
19+
print("Mode: {}".format(mode))
20+
except statistics.StatisticsError:
21+
print("There is no mode.")
22+
23+
# Print the standard deviation
24+
stdev = statistics.stdev(numbers)
25+
print("Standard deviation: {}".format(stdev))

5vowelCount.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write a program to count number of vowels in a string
2+
3+
string = input("Enter your string : ") #User defined
4+
5+
vowel = ('a','e','i','o','u') #Vowels
6+
count = 0
7+
8+
for i in range(len(string)):
9+
if(string[i] in vowel):
10+
count +=1
11+
12+
print("Number of vowel in string is",count)

6removeDupliacte.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# WAP to remove all the duplicate from a string
2+
string = input("Enter your string : ")
3+
x=""
4+
for char in string:
5+
if char not in x:
6+
x = x+char
7+
print(x)
8+
x=list("string")

7SumElement.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# WAP to calculate Sum of elements of a list
2+
list = [5, 7, 9, 1, 3, 4, 6, 5, 8]
3+
sum = 0
4+
5+
for i in range(len(list)):
6+
sum += list[i]
7+
8+
print("Sum of elemens is",sum)

8tupleFromList.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# WAP to create a tuple from a given list having number and their cubes in each tuple.
2+
3+
list = [1, 2, 3, 4, 5]
4+
result = [(num, num**3) for num in list]
5+
print(result)

9studentRecord.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# WAP to Python program to create a Dictionary which has a record of student information.
2+
3+
Dict = {"StdName": None, "Rollno": None, "Admno" :None, "Marks": None}
4+
5+
Dict["StdName"] = input("Enter student name : ")
6+
Dict["Rollno"] = input("Enter student roll number : ")
7+
Dict["Admno"] = input("Enter student admission number : ")
8+
Dict["Marks"] = float(input("Enter student marks(in percent) : "))
9+
10+
print(Dict)

argument.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# WAP to find sum, difference and division using argument with return to value
2+
3+
def add(a, b):
4+
"Returns the sum of two numbers"
5+
return a + b
6+
7+
def subtract(a, b):
8+
"Returns the difference of two numbers"
9+
return a - b
10+
11+
def divide(a, b):
12+
"Returns the division of two numbers"
13+
if b == 0:
14+
return "Error: division by zero"
15+
else:
16+
return a / b
17+
18+
# Get the user input
19+
a = float(input("Enter the first number: "))
20+
b = float(input("Enter the second number: "))
21+
22+
# Call the functions
23+
print("The sum is:", add(a, b))
24+
print("The difference is:", subtract(a, b))
25+
print("The division is:", divide(a, b))

biggest.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# WAP to find the biggest of the two numbers
2+
3+
# Get the user input
4+
a = float(input("Enter the first number: "))
5+
b = float(input("Enter the second number: "))
6+
7+
def maximum(a,b):
8+
9+
if a >= b:
10+
return a
11+
else:
12+
return b
13+
14+
print('The Bigger number is',maximum(a, b))

external.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class none:
2+
def _init_(self, val):
3+
self.val = val
4+
self.left = None
5+
self.right = None
6+
7+
def bfs(root):
8+
if root is None:
9+
return
10+
11+
visited = []
12+
queue = [root]
13+
14+
while queue:
15+
node = queue.pop(0)
16+
visited.append(node.val)
17+
18+
if node.left:
19+
queue.append(node.left)
20+
if node.right:
21+
queue.append(node.right)
22+
23+
return visited
24+
25+
root = Node(1)
26+
root.left = Node(2)
27+
root.right = Node(3)
28+
root.left.left = Node(4)
29+
root.left.right = Node(5)
30+
root.right.left = Node(6)
31+
root.right.right = Node(7)
32+
33+
print(bfs(root)) # Output: [1, 2, 3, 4, 5, 6, 7]

0 commit comments

Comments
 (0)