Merge branch 'main' of https://git.kska.io/sppu-se-comp-codes/DSL
This commit is contained in:
commit
b7b5524006
26
README.md
26
README.md
@ -1,3 +1,29 @@
|
||||
# DSL
|
||||
|
||||
Explore our Data Structure Lab repo: codes, lab manuals, write-ups. Ace your assignments with practical examples and clear guidance.
|
||||
|
||||
---
|
||||
|
||||
In this repository, you'll find codes for Data Structure Lab.
|
||||
|
||||
##Index
|
||||
|
||||
###Codes
|
||||
|
||||
1. [DSL - Assignment 1 (Cricket, Badminton, Football)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-1.py)
|
||||
2. [DSL - Assignment 2 (Marks)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-2.py)
|
||||
3. DSL - Assignment 5 (String) - _PENDING_
|
||||
4. DSL - Assignment 11 (Linear, Sentinel, Binary, Fibonnaci Search) - _PENDING_
|
||||
5. [DSL - Assignment 14 (Selection, Bubble Sorting)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-14.py)
|
||||
|
||||
### Lab Manuals
|
||||
|
||||
1. [Assignment 1 - Cricket, Badminton, Football](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20A_01.pdf)
|
||||
2. [Assignment 2 - Marks](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20A_02.pdf)
|
||||
3. [Assignment 5 - String](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20A_05.pdf)
|
||||
4. [Assignment 11 - Linear, Sentinel, Binary, Fibonnaci Search](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20B_11.pdf)
|
||||
5. [Assignment 14 - Selection, Bubble Sorting](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20B_14.pdf)
|
||||
|
||||
---
|
||||
|
||||
Maintained by [notkshitij](https://git.kska.io/notkshitij) and [TanmaySpamzzz](https://git.kska.io/TanmaySpamzzz)
|
||||
|
117
assignment-1.py
Normal file
117
assignment-1.py
Normal file
@ -0,0 +1,117 @@
|
||||
# DSL Assignment - 1
|
||||
|
||||
# List of players
|
||||
|
||||
cricket_players=[]
|
||||
badminton_players=[]
|
||||
football_players=[]
|
||||
|
||||
# Input values
|
||||
|
||||
## List for cricket players
|
||||
def cricket_in():
|
||||
total=int(input("Total number of students playing cricket: \t"))
|
||||
for i in range(total):
|
||||
players=int(input("Enter roll number: \t"))
|
||||
cricket_players.append(players)
|
||||
print("Roll numbers of", total, "students playing cricket: \t", cricket_players)
|
||||
cricket_in()
|
||||
|
||||
## List for badminton players
|
||||
def badminton_in():
|
||||
total=int(input("Total number of students playing badminton: \t"))
|
||||
for i in range(total):
|
||||
players=int(input("Enter roll number: \t"))
|
||||
badminton_players.append(players)
|
||||
print("Roll numbers of", total, "students playing badminton: \t", badminton_players)
|
||||
badminton_in()
|
||||
|
||||
## List for football players
|
||||
def football_in():
|
||||
total=int(input("Total number of students playing football: \t"))
|
||||
for i in range(total):
|
||||
players=int(input("Enter roll number: \t"))
|
||||
football_players.append(players)
|
||||
print("Roll numbers of", total, "students playing football: \t", football_players)
|
||||
football_in()
|
||||
|
||||
# List of students playing cricket+badminton
|
||||
|
||||
cricket_and_badminton=[]
|
||||
|
||||
def cricket_and_badminton_fn():
|
||||
for i in cricket_players:
|
||||
if i in badminton_players:
|
||||
cricket_and_badminton.append(i)
|
||||
print("Roll numbers of students playing cricket and badminton are: \t", cricket_and_badminton)
|
||||
|
||||
# List of students playing either cricket or badminton but not both
|
||||
|
||||
cricket_or_badminton=[]
|
||||
|
||||
def cricket_or_badminton_fn():
|
||||
for i in cricket_players:
|
||||
if i not in badminton_players:
|
||||
cricket_or_badminton.append(i)
|
||||
for i in badminton_players:
|
||||
if i not in cricket_players:
|
||||
cricket_or_badminton.append(i)
|
||||
print("Roll numbers of students playing either cricket or badminton are: \t", cricket_or_badminton)
|
||||
|
||||
# Number of students playing neither cricket nor badminton
|
||||
|
||||
football_only=[]
|
||||
football_only_1=[]
|
||||
|
||||
def football_only_fn():
|
||||
for i in cricket_players:
|
||||
football_only.append(i)
|
||||
for i in badminton_players:
|
||||
if i not in cricket_players:
|
||||
football_only.append(i)
|
||||
for i in football_players:
|
||||
if i not in football_only:
|
||||
football_only_1.append(i)
|
||||
print("Number of students playing neither cricket nor badminton: \t", len(football_only_1), "\n Roll numbers are:\t", football_only_1)
|
||||
|
||||
# Number of students playing cricket and football but not badminton
|
||||
|
||||
not_badminton=[]
|
||||
|
||||
def not_badminton_fn():
|
||||
for i in badminton_players:
|
||||
if i not in cricket_players:
|
||||
not_badminton.append(i)
|
||||
for i in badminton_players:
|
||||
if i not in football_players:
|
||||
not_badminton.append(i)
|
||||
print("Number of students playing cricket and football but not badminton: \t", len(not_badminton), "\n Roll numbers are:\t", not_badminton)
|
||||
|
||||
# Choosing an option
|
||||
def choose_optn():
|
||||
while True:
|
||||
print("Choose an operation to perform:")
|
||||
print("1. List of students playing cricket and badminton both")
|
||||
print("2. List of students playing either cricket or badminton")
|
||||
print("3. List of students playing neither cricket nor badminton")
|
||||
print("4. List of students playing cricket and football but not badminton")
|
||||
print("5. Exit")
|
||||
optn=int(input("Enter option number (1-5): \t"))
|
||||
if optn==1:
|
||||
cricket_and_badminton_fn()
|
||||
if optn==2:
|
||||
cricket_or_badminton_fn()
|
||||
if optn==3:
|
||||
football_only_fn()
|
||||
if optn==4:
|
||||
not_badminton_fn()
|
||||
if optn==5:
|
||||
print("## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE")
|
||||
quit()
|
||||
else:
|
||||
print("\nPlease choose a valid option.\n")
|
||||
choose_optn()
|
||||
choose_optn()
|
||||
|
||||
## END OF CODE
|
||||
|
62
assignment-14.py
Normal file
62
assignment-14.py
Normal file
@ -0,0 +1,62 @@
|
||||
# Sorting (Selection+Bubble) and Top 5
|
||||
|
||||
marks=[]
|
||||
|
||||
# Function to enter marks of students
|
||||
def input_marks():
|
||||
students=int(input("Enter the number of students:\t"))
|
||||
for i in range(students):
|
||||
marks_in=float(input("Enter the marks (out of 50):\t"))
|
||||
marks.append(marks_in)
|
||||
print("\nThe marks you've entered for ", students, "students are: ", marks, "\n")
|
||||
|
||||
# Function for selection sort
|
||||
def selection():
|
||||
for i in range(len(marks)):
|
||||
min_index=i
|
||||
for j in range(i+1, len(marks)):
|
||||
if marks[j] < marks[min_index]:
|
||||
min_index=j
|
||||
marks[i], marks[min_index] = marks[min_index], marks[i]
|
||||
print("Marks sorted in ascending order using selection sort:\t", marks)
|
||||
|
||||
def bubble():
|
||||
for i in range(len(marks)):
|
||||
for j in range(0, len(marks)-i-1):
|
||||
if marks[j]>marks[j+1]:
|
||||
marks[j], marks[j+1] = marks[j+1], marks[j]
|
||||
print("Marks sorted in ascending order using bubble sort:\t", marks)
|
||||
|
||||
def top5():
|
||||
for i in range(len(marks)):
|
||||
for j in range(0, len(marks)-i-1):
|
||||
if marks[j]>marks[j+1]:
|
||||
marks[j], marks[j+1] = marks[j+1], marks[j]
|
||||
print("Top 5 marks using bubble sorting:\t", marks[::-1])
|
||||
|
||||
|
||||
def choose_optn():
|
||||
while True:
|
||||
print("Choose an option from the menu below:")
|
||||
print("1 -> Input marks")
|
||||
print("2 -> Selection Sorting")
|
||||
print("3 -> Bubble Sorting")
|
||||
print("4 -> Display top 5")
|
||||
print("5 -> Exit")
|
||||
optn=int(input("Choose an option (1-5):\t"))
|
||||
|
||||
if optn==1:
|
||||
input_marks()
|
||||
elif optn==2:
|
||||
selection()
|
||||
elif optn==3:
|
||||
bubble()
|
||||
elif optn==4:
|
||||
top5()
|
||||
elif optn==5:
|
||||
print("## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE")
|
||||
quit()
|
||||
else:
|
||||
print("\nPlease choose a valid option (1-5).\n")
|
||||
choose_optn()
|
||||
choose_optn()
|
92
assignment-2.py
Normal file
92
assignment-2.py
Normal file
@ -0,0 +1,92 @@
|
||||
# DSL - Assignment 2
|
||||
|
||||
students=[]
|
||||
marks=[]
|
||||
total_students_in=int(input("Total number of students are: \t"))
|
||||
|
||||
# Entering marks
|
||||
def total_students_fn():
|
||||
for i in range(total_students_in):
|
||||
marks_in=int(input("Enter marks for DSA subject for each student (out of 50) (enter -1 for absent students): \t"))
|
||||
marks.append(marks_in)
|
||||
print("Marks of", total_students_in, "students in DSA subject are:", marks)
|
||||
|
||||
total_students_fn()
|
||||
|
||||
# Option 1 = Average
|
||||
def average_marks():
|
||||
for i in marks:
|
||||
if i<0:
|
||||
break
|
||||
else:
|
||||
average_calc=sum(marks)/total_students_in
|
||||
print("Average score of", total_students_in, "is: \t", average_calc)
|
||||
|
||||
# Option 2 = Highest and lowest
|
||||
def high_low():
|
||||
mini=marks[0]
|
||||
maxi=marks[0]
|
||||
for i in range (len(marks)):
|
||||
if (maxi<marks[i] and marks[i]>-1):
|
||||
maxi=marks[i]
|
||||
for j in range (len(marks)):
|
||||
if (mini>marks[j] and marks[j]>-1):
|
||||
mini=marks[j]
|
||||
print("Highest marks are: \t", maxi)
|
||||
print("Lowest marks are: \t", mini)
|
||||
|
||||
# Option 3 = Absent
|
||||
def absent():
|
||||
absent_count=0
|
||||
for i in marks:
|
||||
if i==-1:
|
||||
absent_count+=1
|
||||
print("Total number of absent students out of", total_students_in, "are: \t", absent_count)
|
||||
|
||||
# Option 4 = Highest freq
|
||||
def high_freq():
|
||||
freq_count=0
|
||||
for i in range(len(marks)):
|
||||
if (i>=0):
|
||||
count=0
|
||||
for j in range(len(marks)):
|
||||
if (marks[i]==marks[j]):
|
||||
count+=1
|
||||
if (freq_count<count):
|
||||
freq_count=count
|
||||
else:
|
||||
break
|
||||
print("Highest frequency is: \t", freq_count)
|
||||
|
||||
# Choosing an option
|
||||
def choose_optn():
|
||||
while True:
|
||||
print("Choose an operation to perform:")
|
||||
print("1. Average score of all students")
|
||||
print("2. Highest and lowest score out of all students")
|
||||
print("3. Count of students absent for test")
|
||||
print("4. Display marks with highest frequency")
|
||||
print("5. Exit")
|
||||
optn=int(input("Enter option number (1-5): \t"))
|
||||
if optn==1:
|
||||
average_marks()
|
||||
print("Designed and Engineered by Kshitij")
|
||||
elif optn==2:
|
||||
high_low()
|
||||
print("Designed and Engineered by Kshitij")
|
||||
elif optn==3:
|
||||
absent()
|
||||
print("Designed and Engineered by Kshitij")
|
||||
elif optn==4:
|
||||
high_freq()
|
||||
print("Designed and Engineered by Kshitij")
|
||||
elif optn==5:
|
||||
print("## Designed and Engineered by Kshitij\n## END OF CODE.")
|
||||
quit()
|
||||
else:
|
||||
print("\n Invalid option selected. Please choose from range 1 to 5. \n")
|
||||
choose_optn()
|
||||
|
||||
choose_optn()
|
||||
|
||||
## END OF CODE
|
BIN
lab-manuals/Lab Assignment A_01.pdf
Normal file
BIN
lab-manuals/Lab Assignment A_01.pdf
Normal file
Binary file not shown.
BIN
lab-manuals/Lab Assignment A_02.pdf
Normal file
BIN
lab-manuals/Lab Assignment A_02.pdf
Normal file
Binary file not shown.
BIN
lab-manuals/Lab Assignment A_05.pdf
Normal file
BIN
lab-manuals/Lab Assignment A_05.pdf
Normal file
Binary file not shown.
BIN
lab-manuals/Lab Assignment B_11.pdf
Normal file
BIN
lab-manuals/Lab Assignment B_11.pdf
Normal file
Binary file not shown.
BIN
lab-manuals/Lab Assignment B_14.pdf
Normal file
BIN
lab-manuals/Lab Assignment B_14.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user