Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 872a691

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

21 files changed

+718
-0
lines changed

β€Ž1.py

Lines changed: 79 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 22 additions & 0 deletions
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

Lines changed: 33 additions & 0 deletions
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

Lines changed: 42 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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")

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /