Skip to content

Commit 83a3ee6

Browse files
Merge pull request #2 from geekcomputers/master
merge from main.
2 parents 4605cb4 + 2c69b35 commit 83a3ee6

9 files changed

+209
-20
lines changed

4 Digit Number Combinations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ def FourDigitCombinations():
88

99
# Same as above but more pythonic
1010
def oneLineCombinations():
11-
numbers = list(map(lambda x: str(x).zfill(4), [i for i in range(1000)]))
11+
numbers = list(map(lambda x: str(x).zfill(4), [i for i in range(10000)]))
1212
print(numbers)

EncryptionTool.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#GGearing
2+
#Simple encryption script for text
3+
#This was one my first versions of this script
4+
#09/07/2017
5+
6+
text=input("Enter text: ")
7+
PI=3.14159265358979323846264338327950288419716939937510
8+
text=list(text)
9+
values= list()
10+
reverse=list()
11+
def encryptChar(target):
12+
#encrytion algorithm
13+
target=(((target+42)*PI)-449)
14+
return target
15+
16+
def decryptChar(target):
17+
target=(((target+449)/PI)-42)
18+
return target
19+
20+
def encrypt(input_text):
21+
input_text_list=list(input_text)
22+
col_values=list()
23+
for i in range (len(input_text_list)):
24+
current=ord(input_text_list[i])
25+
current=encryptChar(current)
26+
col_values.append(current)
27+
return col_values
28+
29+
def decrypt(enc_text):
30+
enc_list
31+
for i in range (len(input_text_list)):
32+
current=int(decryptChar(values[i]))
33+
current=chr(current)
34+
col_values.append(current)
35+
return col_values
36+
37+
def readAndDecrypt(filename):
38+
file=open(filename,"r")
39+
data=file.read()
40+
datalist=list()
41+
datalistint=list()
42+
actualdata=list()
43+
datalist=data.split(" ")
44+
datalist.remove('')
45+
for i in range(len(datalist)):
46+
datalistint.append(float(datalist[i]))
47+
for i in range(len(datalist)):
48+
current1=int(decryptChar(datalistint[i]))
49+
current1=chr(current1)
50+
actualdata.append(current1)
51+
return actualdata
52+
53+
def readAndEncrypt(filename):
54+
file=open(filename,"r")
55+
data=file.read()
56+
datalist=list(data)
57+
encrypted_list=list()
58+
encrypted_list_str=list()
59+
for i in range(len(datalist)):
60+
current=ord(datalist[i])
61+
current=encryptChar(current)
62+
encrypted_list.append(current)
63+
return encrypted_list
64+
65+
def readAndEncryptAndSave(inp_file,out_file):
66+
enc_list=readAndEncrypt(inp_file)
67+
output=open(out_file,"w")
68+
for i in range(len(enc_list)):
69+
output.write(str(enc_list[i])+" ")
70+
output.close()
71+
72+
def readAndDecryptAndSave(inp_file,out_file):
73+
dec_list=readAndDecrypt(inp_file)
74+
output=open(out_file,"w")
75+
for i in range(len(dec_list)):
76+
output.write(str(dec_list[i]))
77+
output.close()
78+
#encryption
79+
for i in range (len(text)):
80+
current=ord(text[i])
81+
current=encryptChar(current)
82+
values.append(current)
83+
84+
#decryption
85+
for i in range (len(text)):
86+
current=int(decryptChar(values[i]))
87+
current=chr(current)
88+
reverse.append(current)
89+
print(reverse)
90+
91+
#saves encrypted in txt file
92+
output=open("encrypted.txt","w")
93+
for i in range(len(values)):
94+
output.write(str(values[i])+" ")
95+
output.close()
96+
97+
#read and decrypts
98+
print(readAndDecrypt("encrypted.txt"))
99+
100+

QuadraticCalc.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#GGearing
2+
#02/10/2017
3+
#Simple script to calculate the quadratic formula of a sequence of numbers and
4+
#recognises when the sequence isn't quadratic
5+
6+
def findLinear(numbers): ##find a & b of linear sequence
7+
output=[]
8+
a=numbers[1]-numbers[0]
9+
a1=numbers[2]-numbers[1]
10+
if a1==a:
11+
b=numbers[0]-a
12+
return (a,b)
13+
else:
14+
print("Sequence is not linear")
15+
16+
sequence=[]
17+
first_difference=[]
18+
second_difference=[]
19+
for i in range(4): #input
20+
term=str(i+1)
21+
inp=int(input("Enter term "+term+": "))
22+
sequence.append(inp)
23+
24+
for i in range(3):
25+
gradient=sequence[i+1]-sequence[i]
26+
first_difference.append(gradient)
27+
for i in range(2):
28+
gradient=first_difference[i+1]-first_difference[i]
29+
second_difference.append(gradient)
30+
31+
if second_difference[0]==second_difference[1]: #checks to see if consistent
32+
a=second_difference[0]/2
33+
subs_diff=[]
34+
for i in range(4):
35+
n=i+1
36+
num=a*(n*n)
37+
subs_diff.append((sequence[i])-num)
38+
b,c=findLinear(subs_diff)
39+
print("Nth term: "+str(a)+"n^2 + "+str(b)+"n + "+str(c)) #outputs nth term
40+
else:
41+
print("Sequence is not quadratic")
42+

dec_to_hex.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
1-
mydict={
2-
'0':'0','1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'A','11':'B',
3-
'12':'C','13':'D','14':'E','15':'F'
4-
}
5-
dec_num=input('Enter the decimal number\n');
6-
dec_num=int(dec_num)
7-
value=""
8-
while dec_num>0:
9-
value+=mydict[str(dec_num%16)]
10-
dec_num=dec_num//16
11-
hex_value=value[::-1]
12-
print(hex_value)
1+
dec_num=input('Enter the decimal number\n')
2+
print(hex(int(dec_num)))

movie_details

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ browser.addheaders = [('User-agent',
1414
movie_title = raw_input("Enter movie title: ")
1515

1616
movie_types = ('feature', 'tv_movie', 'tv_series', 'tv_episode', 'tv_special',
17-
'mini_series', 'documentary', 'game', 'short', 'video')
17+
'mini_series', 'documentary', 'game', 'short', 'video', 'tvshort')
1818

1919
# Navigate
2020
browser.open('http://www.imdb.com/search/title')

multiplication_table.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
def table(rows, columns):
77
for i in range(1, int(rows) + 1 ): #it's safe to assume that the user would mean 12 rows when they provide 12 as an argument, b'coz 12 will produce 11 rows
8-
print "\t", i,
8+
print ("\t", i,)
99

10-
print "\n\n"
10+
print ("\n\n")
1111

1212
for i in range(1, int(columns) + 1 ):
13-
print i,
13+
print (i),
1414
for j in range(1, int(rows) + 1 ):
15-
print "\t",i*j,
16-
print "\n\n"
15+
print ("\t",i*j,)
16+
print ("\n\n")
1717

1818
table(rows, columns)

nDigitNumberCombinations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ALL the combinations of n digit combo
2+
def nDigitCombinations():
3+
try:
4+
npow = 10**n
5+
numbers=[]
6+
for code in range(npow):
7+
code=str(code).zfill(n)
8+
numbers.append(code)
9+
except:
10+
# handle all other exceptions
11+
pass
12+
return(numbers)

random-sentences.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Generates Random Sentences
2+
3+
Creates a sentence by selecting a word at randowm from each of the lists in
4+
the following order: 'article', 'nounce', 'verb', 'preposition',
5+
'article' and 'noun'.
6+
7+
The second part produce a short story consisting of several of
8+
these sentences -- Random Note Writer!!
9+
"""
10+
11+
import random
12+
13+
article = ["the", "a", "one", "some", "any"]
14+
noun = ["boy", "girl", "dog", "town", "car"]
15+
verb = ["drove", "jumped", "ran", "walked", "skipped"]
16+
preposition = ["to", "from", "over", "under", "on"]
17+
18+
19+
def random_sentence():
20+
"""Creates random and return sentences."""
21+
22+
sentence = ""
23+
sentence += article[random.randint(0, 4)] + " " + noun[random.randint(
24+
0, 4)] + " "
25+
sentence += verb[random.randint(0, 4)] + " " + preposition[random.randint(
26+
0, 4)] + " "
27+
sentence += article[random.randint(0, 4)] + " " + noun[random.randint(
28+
0, 4)] + ". "
29+
sentence = sentence[0].upper() + sentence[1:]
30+
31+
return sentence
32+
33+
34+
# prints random sentences
35+
for x in range(20):
36+
print(random_sentence())
37+
38+
print()
39+
print()
40+
41+
# creates short story
42+
story = ""
43+
for x in range(20):
44+
story += random_sentence()
45+
46+
print(story)

xkcd_downloader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def main():
3131

3232
# gets comic name from the image src url
3333
comic_name = image_src.split('/')[-1]
34-
comic_name = comic_name[:-4]
3534

3635
# save location of comic
3736
comic_location = os.getcwd() + '/comics/'

0 commit comments

Comments
 (0)