Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions 1st Year/09. String Operations/string_fun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## To implement user-defined function for string functions
def slen(str):
count = 0
for item in str:
count += 1
return count


def scomp(str_first, str_second):
if slen(str_first) != slen(str_second):
return False

for i in range(slen(str_first)):
if str_first[i] != str_second[i]:
return False

return True


def scat(str_first, str_second):
return str_first + str_second


if __name__ == "__main__":
str1 = input("Enter String 1: ")
str2 = input("Enter string 2: ")

print("Lenght of String 1:", slen(str1))
print("Length of String 2:", slen(str2))

if scomp(str1, str2):
print("The strings {}, {} are equal.".format(str1, str2))
else:
print("The strings {}, {} are not equal.".format(str1, str2))

print("The concatenated string is: {}".format(scat(str1, str2)))

"""
Sample output
Enter String 1: ads
Enter string 2: asdfsdf

Lenght of String 1: 3
Length of String 2: 7
The strings ads, asdfsdf are not equal.
The concatenated string is: adsasdfsdf

"""
40 changes: 40 additions & 0 deletions 1st Year/10. Bubble Sort/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Program to implement bubble sort

def bubble_sort(arr):
length = len(arr)
for i in range(length - 1):
for j in range(0, length - i - 1):
if arr[j] > arr[j + 1]:
## Swapping the right adjacent number
t = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = t
return arr


if __name__ == "__main__":
input_arr = []
num = int(input("Enter the number of numbers: "))
print("Enter the array: ")

for item in range(0, num):
input_arr.append(int(input()))

print("The given array is : {}".format(input_arr))

print("Array after bubble sorting is: {}".format(bubble_sort(input_arr)))
exit(0)

'''
Sample output
Enter the number of numbers: 5
Enter the array:
3
1
6
4
8
The given array is : [3, 1, 6, 4, 8]
Array after bubble sorting is: [1, 3, 4, 6, 8]

'''