Skip to content

Commit 485f93f

Browse files
committed
Merge branch 'master' of git://github.com/gerroo/Python
2 parents 432c62d + 5492681 commit 485f93f

File tree

8 files changed

+91
-35
lines changed

8 files changed

+91
-35
lines changed

Maths/3n+1.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def main():
2+
def n31(a):# a = initial number
3+
c = 0
4+
l = [a]
5+
while a != 1:
6+
if a % 2 == 0:#if even divide it by 2
7+
a = a // 2
8+
elif a % 2 == 1:#if odd 3n+1
9+
a = 3*a +1
10+
c += 1#counter
11+
l += [a]
12+
print(a)#optional print
13+
print("It took {0} steps.".format(c))#optional finish
14+
return l , c
15+
print(n31(43))
16+
17+
if __name__ == '__main__':
18+
main()

Maths/FindMin.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def main():
2+
def findMin(x):
3+
minNum = x[0]
4+
for i in x:
5+
if minNum > i:
6+
minNum = i
7+
return minNum
8+
9+
print(findMin([0,1,2,3,4,5,-3,24,-56])) # = -56
10+
11+
if __name__ == '__main__':
12+
main()

ciphers/base64_cipher.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import base64
2+
3+
def main():
4+
inp = input('->')
5+
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
6+
b64encoded = base64.b64encode(encoded) #b64encoded the encoded string
7+
print(b64encoded)
8+
print(base64.b64decode(b64encoded).decode('utf-8'))#decoded it
9+
10+
if __name__ == '__main__':
11+
main()
File renamed without changes.

simple_client/client.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# client.py
2+
3+
import socket
4+
5+
HOST, PORT = '127.0.0.1', 1400
6+
7+
s = socket.socket(
8+
9+
socket.AF_INET, # ADDRESS FAMILIES
10+
#Name Purpose
11+
#AF_UNIX, AF_LOCAL Local communication
12+
#AF_INET IPv4 Internet protocols
13+
#AF_INET6 IPv6 Internet protocols
14+
#AF_APPLETALK Appletalk
15+
#AF_BLUETOOTH Bluetooth
16+
17+
18+
socket.SOCK_STREAM # SOCKET TYPES
19+
#Name Way of Interaction
20+
#SOCK_STREAM TCP
21+
#SOCK_DGRAM UDP
22+
)
23+
s.connect((HOST, PORT))
24+
25+
s.send('Hello World'.encode('ascii'))#in UDP use sendto()
26+
data = s.recv(1024)#in UDP use recvfrom()
27+
28+
s.close()#end the connection
29+
print(repr(data.decode('ascii')))

simple_client/server.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# server.py
2+
3+
import socket
4+
5+
HOST, PORT = '127.0.0.1', 1400
6+
7+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#refer to client.py
8+
s.bind((HOST, PORT))
9+
s.listen(1)#listen for 1 connection
10+
11+
conn, addr = s.accept()#start the actual data flow
12+
13+
print('connected to:', addr)
14+
15+
while 1:
16+
data = conn.recv(1024).decode('ascii')#receive 1024 bytes and decode using ascii
17+
if not data:
18+
break
19+
conn.send((data + ' [ addition by server ]').encode('ascii'))
20+
21+
conn.close()

simple_client_server/client.py

-14
This file was deleted.

simple_client_server/server.py

-21
This file was deleted.

0 commit comments

Comments
 (0)