File tree 9 files changed +103
-6
lines changed
9 files changed +103
-6
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,11 @@ def n31(a):# a = initial number
9
9
a = 3 * a + 1
10
10
c += 1 #counter
11
11
l += [a ]
12
- print (a )#optional print
13
- print ("It took {0} steps." .format (c ))#optional finish
12
+
14
13
return l , c
15
14
print (n31 (43 ))
16
-
15
+ print (n31 (98 )[0 ][- 1 ])# = a
16
+ print ("It took {0} steps." .format (n31 (13 )[1 ]))#optional finish
17
+
17
18
if __name__ == '__main__' :
18
19
main ()
Original file line number Diff line number Diff line change
1
+ def absVal (num ):
2
+ """
3
+ Function to fins absolute value of numbers.
4
+ >>>absVal(-5)
5
+ 5
6
+ >>>absVal(0)
7
+ 0
8
+ """
9
+ if num < 0 :
10
+ return - num
11
+ else :
12
+ return num
13
+
14
+ def main ():
15
+ print (absVal (- 34 )) # = 34
16
+
17
+ if __name__ == '__main__' :
18
+ main ()
Original file line number Diff line number Diff line change
1
+ from abs import absVal
2
+ def absMax (x ):
3
+ """
4
+ >>>absMax([0,5,1,11])
5
+ 11
6
+ >>absMax([3,-10,-2])
7
+ -10
8
+ """
9
+ j = x [0 ]
10
+ for i in x :
11
+ if absVal (i ) < j :
12
+ j = i
13
+ return j
14
+ #BUG: i is apparently a list, TypeError: '<' not supported between instances of 'list' and 'int' in absVal
15
+
16
+
17
+ def main ():
18
+ a = [1 ,2 ,- 11 ]
19
+ print (absVal (a )) # = -11
20
+
21
+ if __name__ == '__main__' :
22
+ main ()
Original file line number Diff line number Diff line change
1
+ from abs import absVal
2
+ def absMin (x ):
3
+ """
4
+ >>>absMin([0,5,1,11])
5
+ 0
6
+ >>absMin([3,-10,-2])
7
+ -2
8
+ """
9
+ j = x [0 ]
10
+ for i in x :
11
+ if absVal (i ) < j :
12
+ j = i
13
+ return j
14
+
15
+ def main ():
16
+ a = [1 ,2 ,- 11 ]
17
+ print (absMin (a )) # = 1
18
+
19
+ if __name__ == '__main__' :
20
+ main ()
Original file line number Diff line number Diff line change
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
+ b16encoded = base64 .b16encode (encoded ) #b16encoded the encoded string
7
+ print (b16encoded )
8
+ print (base64 .b16decode (b16encoded ).decode ('utf-8' ))#decoded it
9
+
10
+ if __name__ == '__main__' :
11
+ main ()
Original file line number Diff line number Diff line change
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
+ b32encoded = base64 .b32encode (encoded ) #b32encoded the encoded string
7
+ print (b32encoded )
8
+ print (base64 .b32decode (b32encoded ).decode ('utf-8' ))#decoded it
9
+
10
+ if __name__ == '__main__' :
11
+ main ()
Original file line number Diff line number Diff line change
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
+ a85encoded = base64 .a85encode (encoded ) #a85encoded the encoded string
7
+ print (a85encoded )
8
+ print (base64 .a85decode (a85encoded ).decode ('utf-8' ))#decoded it
9
+
10
+ if __name__ == '__main__' :
11
+ main ()
Original file line number Diff line number Diff line change 1
1
arr = [10 , 20 , 30 , 40 ]
2
- arr [1 ] = 30
2
+ arr [1 ] = 30 # set element 1 (20) of array to 30
3
3
print (arr )
Original file line number Diff line number Diff line change 1
1
# Fibonacci Sequence Using Recursion
2
2
3
3
def recur_fibo (n ):
4
- return n if n <= 1 else (recur_fibo (n - 1 ) + recur_fibo (n - 2 ))
5
-
4
+ if n <= 1 :
5
+ return n
6
+ else :
7
+ (recur_fibo (n - 1 ) + recur_fibo (n - 2 ))
8
+
6
9
def isPositiveInteger (limit ):
7
10
return limit >= 0
8
11
You can’t perform that action at this time.
0 commit comments