Skip to content
18 changes: 18 additions & 0 deletions Python/List/interchangefirstlastele.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Python3 program to swap first
# and last element of a list

# Swap function
def swapList(newList):
size = len(newList)

# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp

return newList

# Driver code
newList = [12, 35, 9, 56, 24]

print(swapList(newList))
14 changes: 14 additions & 0 deletions Python/List/swap2elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Python3 program to swap elements
# at given positions

# Swap function
def swapPositions(list, pos1, pos2):

list[pos1], list[pos2] = list[pos2], list[pos1]
return list

# Driver function
List = [23, 65, 19, 90]
pos1, pos2 = 1, 3

print(swapPositions(List, pos1-1, pos2-1))
23 changes: 23 additions & 0 deletions Python/Matrix/add2matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Program to add two matrices using nested loop

X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]

Y = [[9,8,7],
[6,5,4],
[3,2,1]]


result = [[0,0,0],
[0,0,0],
[0,0,0]]

# iterate through rows
for i in range(len(X)):
# iterate through columns
for j in range(len(X[0])):
result[i][j] = X[i][j] + Y[i][j]

for r in result:
print(r)
28 changes: 28 additions & 0 deletions Python/Matrix/multipy2matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Program to multiply two matrices using nested loops

# take a 3x3 matrix
A = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]

# take a 3x4 matrix
B = [[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]

result = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]

# iterating by row of A
for i in range(len(A)):

# iterating by column by B
for j in range(len(B[0])):

# iterating by rows of B
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]

for r in result:
print(r)
14 changes: 14 additions & 0 deletions Python/string/checkpalindrome .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# function which return reverse of a string

def isPalindrome(s):
return s == s[::-1]


# Driver code
s = "malayalam"
ans = isPalindrome(s)

if ans:
print("Yes")
else:
print("No")
16 changes: 16 additions & 0 deletions Python/string/reversewords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Function to reverse words of string

def rev_sentence(sentence):

# first split the string into words
words = sentence.split(' ')

# then reverse the split string list and join using space
reverse_sentence = ' '.join(reversed(words))

# finally return the joined string
return reverse_sentence

if __name__ == "__main__":
input = 'geeks quiz practice code'
print (rev_sentence(input))
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# DS
# REPOSITORY TO HOLD PROGRAMS FOR VARIOUS DATA STRUCTURES

Pick a language of your choice and if you don't find a data structure implemented in the language feel free to contribute
20 changes: 20 additions & 0 deletions certificate-generator/Manas Kumar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

----------------------------------------------------------------------------
| Certificate of Completion |
| |
| |
| This is to certify that Manas Kumar has successfully completed the |
| course in Micro Biology. |
| |
| |
| |
| |
| ______________________ _______________ |
| Signature of Instructor Signature of HOD |
| |
| |
| |
| |
| |
---------------------------------------------------------------------------

20 changes: 20 additions & 0 deletions certificate-generator/Niraj Kumar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

----------------------------------------------------------------------------
| Certificate of Completion |
| |
| |
| This is to certify that Niraj Kumar has successfully completed the |
| course in Micro Biology. |
| |
| |
| |
| |
| ______________________ _______________ |
| Signature of Instructor Signature of HOD |
| |
| |
| |
| |
| |
---------------------------------------------------------------------------

20 changes: 20 additions & 0 deletions certificate-generator/Prakash Kumar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

----------------------------------------------------------------------------
| Certificate of Completion |
| |
| |
| This is to certify that Prakash Kumar has successfully completed the |
| course in Micro Biology. |
| |
| |
| |
| |
| ______________________ _______________ |
| Signature of Instructor Signature of HOD |
| |
| |
| |
| |
| |
---------------------------------------------------------------------------

21 changes: 21 additions & 0 deletions certificate-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## CERTIFICATE GENERATOR



A python script to read names from a txt file and generate txt files in the same directory



#### HOW TO RUN THE SCRIPT

- extract the zip file

- open the terminal and change directory to extracted zip folder

- write comma separated names in input.txt ( a sample of it is added here )

- in the terminal type `python -u main.py`

- if the input file exists and and it has names txt files with name as file name will be generated

- for the sample input files, output certificates are attached
1 change: 1 addition & 0 deletions certificate-generator/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar
49 changes: 49 additions & 0 deletions certificate-generator/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'''
authored by palak thapar
'''

import os
names = []
input_file = 'input.txt'
try:

if os.stat(input_file).st_size == 0: # check for an empty file
print('Sorry, the file {input_file} is empty'.format(input_file=input_file))
else:
for line in open(input_file, 'r'):
for name in line.strip().split(','):
names.append(name)
except FileNotFoundError: # check for a non-existing file
msg = 'Sorry, the file {input_file} does not exist.'.format(input_file=input_file)
print(msg)

for name in names:
with open(name + '.txt', 'w') as wp:
print("generating certificate for {name}".format(name=name))
content = \
'''
----------------------------------------------------------------------------
| Certificate of Completion |
| |
| |
| This is to certify that {name} has successfully completed the |
| course in Micro Biology. |
| |
| |
| |
| |
| ______________________ _______________ |
| Signature of Instructor Signature of HOD |
| |
| |
| |
| |
| |
---------------------------------------------------------------------------
'''
wp.write(content.format(name=name)) # writing the content to each file
wp.close() # closing the file

# a check for success
print("successfully generated certificate for {name}".format(name=name))
print()
2 changes: 2 additions & 0 deletions print("hello world").py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print("hello world")
print("Hacktoberfest20210908868")