Merge branch 'master' of git://github.com/gerroo/Python into gerroo-master

This commit is contained in:
Harshil 2018-11-04 16:04:29 +01:00
commit 5db9d2e54a
9 changed files with 103 additions and 6 deletions

View File

@ -9,10 +9,11 @@ def main():
a = 3*a +1
c += 1#counter
l += [a]
print(a)#optional print
print("It took {0} steps.".format(c))#optional finish
return l , c
print(n31(43))
print(n31(98)[0][-1])# = a
print("It took {0} steps.".format(n31(13)[1]))#optional finish
if __name__ == '__main__':
main()

18
Maths/abs.py Normal file
View File

@ -0,0 +1,18 @@
def absVal(num):
"""
Function to fins absolute value of numbers.
>>>absVal(-5)
5
>>>absVal(0)
0
"""
if num < 0:
return -num
else:
return num
def main():
print(absVal(-34)) # = 34
if __name__ == '__main__':
main()

22
Maths/absMax.py Normal file
View File

@ -0,0 +1,22 @@
from abs import absVal
def absMax(x):
"""
>>>absMax([0,5,1,11])
11
>>absMax([3,-10,-2])
-10
"""
j = x[0]
for i in x:
if absVal(i) < j:
j = i
return j
#BUG: i is apparently a list, TypeError: '<' not supported between instances of 'list' and 'int' in absVal
def main():
a = [1,2,-11]
print(absVal(a)) # = -11
if __name__ == '__main__':
main()

20
Maths/absMin.py Normal file
View File

@ -0,0 +1,20 @@
from abs import absVal
def absMin(x):
"""
>>>absMin([0,5,1,11])
0
>>absMin([3,-10,-2])
-2
"""
j = x[0]
for i in x:
if absVal(i) < j:
j = i
return j
def main():
a = [1,2,-11]
print(absMin(a)) # = 1
if __name__ == '__main__':
main()

11
ciphers/base16.py Normal file
View File

@ -0,0 +1,11 @@
import base64
def main():
inp = input('->')
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
b16encoded = base64.b16encode(encoded) #b16encoded the encoded string
print(b16encoded)
print(base64.b16decode(b16encoded).decode('utf-8'))#decoded it
if __name__ == '__main__':
main()

11
ciphers/base32.py Normal file
View File

@ -0,0 +1,11 @@
import base64
def main():
inp = input('->')
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
b32encoded = base64.b32encode(encoded) #b32encoded the encoded string
print(b32encoded)
print(base64.b32decode(b32encoded).decode('utf-8'))#decoded it
if __name__ == '__main__':
main()

11
ciphers/base85.py Normal file
View File

@ -0,0 +1,11 @@
import base64
def main():
inp = input('->')
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
a85encoded = base64.a85encode(encoded) #a85encoded the encoded string
print(a85encoded)
print(base64.a85decode(a85encoded).decode('utf-8'))#decoded it
if __name__ == '__main__':
main()

View File

@ -1,3 +1,3 @@
arr = [10, 20, 30, 40]
arr[1] = 30
arr[1] = 30 # set element 1 (20) of array to 30
print(arr)

View File

@ -1,8 +1,11 @@
# Fibonacci Sequence Using Recursion
def recur_fibo(n):
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
if n <= 1:
return n
else:
(recur_fibo(n-1) + recur_fibo(n-2))
def isPositiveInteger(limit):
return limit >= 0