Skip to content

Commit 4628ffe

Browse files
authored
Add files via upload
0 parents  commit 4628ffe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1573
-0
lines changed

Cipher.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Thu Nov 15 17:12:11 2018
5+
6+
@author: manveet
7+
"""
8+
9+
import string
10+
11+
dict = {}
12+
data=""
13+
file=open("op_txt.txt","w")
14+
for i in range(len(string.ascii_letters)):
15+
dict[string.ascii_letters[i]]=string.ascii_letters[i-1]
16+
print(dict)
17+
with open("ip_file.txt") as f:
18+
while True:
19+
c=f.read(1)
20+
if not c:
21+
print("End of file")
22+
break
23+
if c in dict:
24+
data=dict[c]
25+
else:
26+
data=c
27+
file.write(data)
28+
print(data)
29+
file.close()
30+

Facebook_data.xlsx

5.88 KB
Binary file not shown.

Flames.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sun Nov 25 22:39:44 2018
5+
6+
@author: manveet
7+
"""
8+
import string
9+
10+
def remove_matching_letters(l1,l2):
11+
for i in range(len(l1)):
12+
for j in range(len(l2)):
13+
if l1[i] == l2[j]:
14+
c = l1[i]
15+
l1.remove(c)
16+
l2.remove(c)
17+
l = l1+['*']+l2
18+
return[l,True]
19+
l=l1+['*']+l2
20+
return [l,False]
21+
22+
p1 = input("Enter first person name: ")
23+
p2 = input("Enter second person name: ")
24+
p1 = p1.lower()
25+
p1 = p1.replace(" ","")
26+
p2 = p2.lower()
27+
p2 = p2.replace(" ","")
28+
29+
30+
l1 = list(p1)
31+
l2 = list(p2)
32+
33+
proceed = True
34+
while proceed:
35+
ret_list = remove_matching_letters(l1,l2)
36+
con_list = ret_list[0]
37+
proceed = ret_list[1]
38+
star_index = con_list.index('*')
39+
l1 = con_list[ : star_index]
40+
l2 = con_list[star_index+1 : ]
41+
42+
count = len(l1) + len(l2)
43+
result = ['Friends','Love','Affection','Marriage','Enemy','Siblings']
44+
45+
while len(result)>1:
46+
split_index = (count%len(result))-1
47+
if split_index >= 0:
48+
right = result[split_index+1:]
49+
left = result[:split_index]
50+
result = right+left
51+
else:
52+
result=result[:len(result)-1]
53+
54+
print(result[0])
55+
56+
57+
58+
59+
60+
61+
62+

amb.png

57 KB
Loading

anagram.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Nov 23 15:18:24 2018
5+
6+
@author: manveet
7+
"""
8+
9+
str1 = input("Enter the first string ")
10+
str2=input("enter the second string ")
11+
count1 = 0
12+
i=0
13+
while(i<len(str1)):
14+
count1 = count1+ord(str1[i])
15+
i = i+1
16+
count2 = 0
17+
i=0
18+
while(i<len(str2)):
19+
count2 = count2+ord(str2[i])
20+
i = i+1
21+
if(count1 == count2):
22+
print("These are Anagrams")
23+
else:
24+
print("These are not Anagrams")
25+
26+
27+

answer.wav

31.3 KB
Binary file not shown.

bdaytwin.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Tue Nov 13 17:04:12 2018
5+
6+
@author: manveet
7+
"""
8+
9+
import random
10+
import datetime
11+
birthday=[]
12+
i=0
13+
while(i<50):
14+
year=random.randint(1895,2017)
15+
if(year%4==0 and year%100!=0 or year%400==0):
16+
leap=1
17+
else:
18+
leap=0
19+
month=random.randint(1,12)
20+
if(month == 2 and leap==1):
21+
day=random.randint(1,29)
22+
elif(month==2 and leap==0):
23+
day=random.randint(1,28)
24+
elif(month==7 or month==8):
25+
day=random.randint(1,31)
26+
elif(month%2!=0 and month<7):
27+
day=random.randint(1,31)
28+
elif(month%2==0 and month>7 and month<12):
29+
day=random.randint(1,31)
30+
else:
31+
day=random.randint(1,30)
32+
dd=datetime.date(year,month,day)
33+
day_of_year=dd.timetuple().tm_yday
34+
i=i+1
35+
birthday.append(day_of_year)
36+
birthday.sort()
37+
i=0
38+
while(i<50):
39+
print(birthday[i])
40+
i=i+1

binary_search.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed Nov 14 21:46:17 2018
5+
6+
@author: manveet
7+
"""
8+
def binary_search(a,x):
9+
first_pos = 0
10+
last_pos = len(a)-1
11+
flag=0
12+
count=0
13+
while(first_pos <= last_pos and flag==0):
14+
count+=1
15+
mid = (first_pos+last_pos)//2
16+
if(x == a[mid]):
17+
flag = 1
18+
print("the elemnt is present at pos : "+str(mid))
19+
print("The number of iterations are: "+str(count))
20+
return
21+
else:
22+
if(x<a[mid]):
23+
last_pos = mid-1
24+
else:
25+
first_pos = mid+1
26+
print("the number is not present")
27+
a = []
28+
for i in range(1,1001):
29+
a.append(i)
30+
31+
binary_search(a,74)
32+
33+
34+
35+
36+

binary_search_recursion.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Nov 16 11:44:40 2018
5+
6+
@author: manveet
7+
"""
8+
l=[1,2,3,4,5]
9+
def binary_search(l,x,start,end):
10+
#Base case is one element in the list
11+
if start==end:
12+
if l[start]==x:
13+
return start
14+
else:
15+
return -1
16+
else:
17+
mid=int((start+end)/2)
18+
if(x==l[mid]):
19+
return mid
20+
else:
21+
if(x>l[mid]):
22+
return binary_search(l,x,mid+1,end)
23+
elif(x<l[mid]):
24+
return binary_search(l,x,start,mid-1)
25+
x=int(input("eneter searh key : "))
26+
index=binary_search(l,x,0,len(l)-1)
27+
if(index == x):
28+
print(x,' Element not found ')
29+
else:
30+
print(x, ' is found at position ', str(index+1))
31+
32+
33+
34+
35+
36+
37+

bubblesort.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed Nov 14 21:20:20 2018
5+
6+
@author: manveet
7+
"""
8+
def bubble(a):
9+
n=len(a)
10+
for i in range(n):
11+
for j in range(0,n-i-1):
12+
if(a[j]>a[j+1]):
13+
tmp = a[j]
14+
a[j] = a[j+1]
15+
a[j+1] = tmp
16+
17+
a = [5,1,4,2,8]
18+
bubble(a)
19+
20+
for i in a:
21+
print(i)

data_file.ods

9.85 KB
Binary file not shown.

dict.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed Nov 14 00:25:54 2018
5+
6+
@author: manveet
7+
"""
8+

dna_data.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01010101011100011001010101010101010010000100100100010010111100100100100100100100001010010001000100100100101010101010101010010101010101010101010101001101010101010101010010101010

fact_recurrsion.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Nov 16 11:37:00 2018
5+
6+
@author: manveet
7+
"""
8+
def fact(n):
9+
if(n==1 or n==0):
10+
return 1
11+
elif(n>1):
12+
return n*fact(n-1)
13+
else:
14+
print('Incorrect Number')

fiibonacci_recurssion.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Nov 16 12:06:48 2018
5+
6+
@author: manveet
7+
"""
8+
# =============================================================================
9+
# def fibonnaci(i):
10+
# first = 0
11+
# second = 1
12+
# print(first)
13+
# print(second)
14+
# third=first+second
15+
# while(True):
16+
# if(third == i):
17+
# break
18+
# else:
19+
# first = second
20+
# second = third
21+
# third = first+second
22+
# print(third)
23+
#
24+
# =============================================================================
25+
def fibonnaci(n):
26+
if n<2:
27+
return n
28+
else:
29+
return fibonnaci(n-1)+fibonnaci(n-2)
30+
print(fibonnaci(4))
31+
32+
33+
34+
35+

file.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sat Nov 10 23:38:28 2018
5+
6+
@author: manveet
7+
"""
8+
9+
with open("file1.txt","r+") as myfile:
10+
print(myfile.read())
11+
myfile.write("I am fine")
12+
myfile.close()

file1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I am fineI am fine

filehandling.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sat Nov 10 23:57:04 2018
5+
6+
@author: manveet
7+
"""
8+
import random
9+
10+
def evolve(x):
11+
ind = random.randint(0,len(x)-1)
12+
p=random.randint(1,100)
13+
print(p,ind)
14+
if (p==1):
15+
if(x[ind]=='0'):
16+
x[ind]=='1'
17+
else:
18+
x[ind]=='0'
19+
with open("dna_data.txt","r+") as myfile:
20+
x = myfile.read()
21+
x = list(x)
22+
for i in range(0,10000):
23+
evolve(x)
24+
print(x)

0 commit comments

Comments
 (0)