Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37c73bc

Browse files
author
vedant22
authored
Merge pull request #1 from geekcomputers/master
python print
2 parents def2053 + 9f36518 commit 37c73bc

Some content is hidden

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

57 files changed

+2462
-158
lines changed

4 Digit Number Combinations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ def FourDigitCombinations():
33
numbers=[]
44
for code in range(10000):
55
code=str(code).zfill(4)
6-
print code,
6+
print(code)
77
numbers.append(code)
8+
9+
# Same as above but more pythonic
10+
def oneLineCombinations():
11+
numbers = list(map(lambda x: str(x).zfill(4), [i for i in range(10000)]))
12+
print(numbers)

CountMillionCharacter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
That even our corn shall seem as light as chaff
248248
And good from bad find no partition.
249249
ARCHBISHOP OF YORK
250-
No, no, my lord. Note this; the king is weary
250+
No, no, my lord. Note this; the king is weary
251251
Of dainty and such picking grievances:
252252
For he hath found to end one doubt by death
253253
Revives two greater in the heirs of life,

CountMillionCharacters-Variations/variation1.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@ def countchars(filename):
1717
else:
1818
input_func = raw_input
1919

20-
inputFile = input_func("File Name : ")
21-
print(countchars(inputFile))
20+
is_exist=True
21+
#Try to open file if exist else raise exception and try again
22+
while(is_exist):
23+
try:
24+
inputFile = input_func("File Name : ")
25+
print(countchars(inputFile))
26+
is_exist = False #Set False if File Name found
27+
except FileNotFoundError:
28+
print("File not found...Try again!")
29+

Cricket_score.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import bs4 as bs
2+
from urllib import request
3+
from win10toast import ToastNotifier
4+
5+
toaster = ToastNotifier()
6+
7+
url = 'http://www.cricbuzz.com/cricket-match/live-scores'
8+
9+
sauce = request.urlopen(url).read()
10+
soup = bs.BeautifulSoup(sauce,"lxml")
11+
#print(soup)
12+
score = []
13+
results = []
14+
#for live_matches in soup.find_all('div',attrs={"class":"cb-mtch-lst cb-col cb-col-100 cb-tms-itm"}):
15+
for div_tags in soup.find_all('div', attrs={"class": "cb-lv-scrs-col text-black"}):
16+
score.append(div_tags.text)
17+
for result in soup.find_all('div', attrs={"class": "cb-lv-scrs-col cb-text-complete"}):
18+
results.append(result.text)
19+
20+
21+
print(score[0],results[0])
22+
toaster.show_toast(title=score[0],msg=results[0])
23+

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+

Google_News.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ def news():
66
#my_url="https://news.google.com/news/rss"
77
my_url="https://news.google.com/news/rss?ned=in&hl=en-IN"
88
#To open the Given URL
9-
Client=urlopen(my_url)
9+
Client=urlopen(my_url)
10+
s_url ="https://news.google.com/news/headlines/section/topic/SPORTS.en_in/Sports?ned=in&hl=en-IN&gl=IN"
11+
Client=urlopen(s_url)
12+
13+
1014

1115
xml_page=Client.read()
1216
Client.close()
@@ -24,3 +28,4 @@ def news():
2428

2529

2630
news()
31+

Koch Curve/README.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
The Koch snowflake (also known as the Koch curve, Koch star, or Koch island) is a mathematical curve and one of the earliest fractal curves
2+
to have been described. It is based on the Koch curve, which appeared in a 1904 paper titled �On a continuous curve without tangents,
3+
constructible from elementary geometry� by the Swedish mathematician Helge von Koch.
4+
5+
How to construct one:
6+
7+
Step 1:
8+
Draw an equilateral triangle. You can draw it with a compass or protractor, or just eyeball it if you don't want to spend too much time draw
9+
ing the snowflake. It's best if the length of the sides are divisible by 3, because of the nature of this fractal. This will become clear
10+
in the next few steps.
11+
12+
Step 2:
13+
Divide each side in three equal parts. This is why it is handy to have the sides divisible by three.
14+
15+
Step 3:
16+
Draw an equilateral triangle on each middle part. Measure the length of the middle third to know the length of the sides of these new
17+
triangles.
18+
19+
Step 4:
20+
Divide each outer side into thirds. You can see the 2nd generation of triangles covers a bit of the first. These three line segments
21+
shouldn't be parted in three.
22+
23+
Step 5:
24+
Draw an equilateral triangle on each middle part. Note how you draw each next generation of parts that are one 3rd of the mast one.
25+
26+
Step 6:
27+
Repeat until you're satisfied with the amount of iterations. It will become harder and harder to accurately draw the new triangles, but
28+
with a fine pencil and lots of patience you can reach the 8th iteration. The one shown in the picture is a Koch snowflake of the 4th
29+
iteration.
30+
31+
Step 7:
32+
Decorate your snowflake how you like it. You can colour it, cut it out, draw more triangles on the inside, or just leave it the way it is.
33+
34+
35+
Reference Links:
36+
http://www.geeksforgeeks.org/koch-curve-koch-snowflake/
37+
https://www.wikihow.com/Draw-the-Koch-Snowflake
38+
https://en.wikipedia.org/wiki/Koch_snowflake

Koch Curve/koch curve.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#importing the libraries
2+
#turtle standard graphics library for python
3+
from turtle import *
4+
5+
#function to create koch snowflake or koch curve
6+
def snowflake(lengthSide, levels):
7+
if levels == 0:
8+
forward(lengthSide)
9+
return
10+
lengthSide /= 3.0
11+
snowflake(lengthSide, levels-1)
12+
left(60)
13+
snowflake(lengthSide, levels-1)
14+
right(120)
15+
snowflake(lengthSide, levels-1)
16+
left(60)
17+
snowflake(lengthSide, levels-1)
18+
19+
#main function
20+
if __name__ == "__main__":
21+
speed(0) #defining the speed of the turtle
22+
length = 300.0 #
23+
penup() #Pull the pen up – no drawing when moving.
24+
#Move the turtle backward by distance, opposite to the direction the turtle is headed.
25+
#Do not change the turtle’s heading.
26+
backward(length/2.0)
27+
pendown()
28+
for i in range(3):
29+
#Pull the pen down – drawing when moving.
30+
snowflake(length, 4)
31+
right(120)
32+
#To control the closing windows of the turtle
33+
mainloop()

Koch Curve/output_2.mp4

620 KB
Binary file not shown.

Print_List_of_Even_Numbers.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
#user can give in put now
2-
#pyhton3
1+
#user can give input now
2+
#python3
3+
4+
import sys
5+
6+
if sys.version_info[0]==2:
7+
version=2
8+
else:
9+
version=3
10+
11+
if version==2:
12+
n=input('Enter number of even numbers to print: ')
13+
printed=0
14+
numbers=0
15+
while printed!=n:
16+
if numbers%2==0:
17+
print numbers,
18+
printed+=1
19+
numbers+=1
20+
21+
if version==3:
22+
print ([x for x in range(int(input()),int(input())) if not x%2])
23+
24+
325

4-
print ([x for x in range(int(input()),int(input())) if not x%2])

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+

0 commit comments

Comments
 (0)