diff --git a/Week1/run.py b/Week1/run.py index be6df67..0498ea1 100644 --- a/Week1/run.py +++ b/Week1/run.py @@ -5,7 +5,12 @@ Problem - 0 Print the odd values in the given array ''' + arr = [5,99,36,54,88] + +for i in arr: + if i % 2 != 0: + print(i," ") ## Code Here ''' @@ -13,10 +18,24 @@ Print all the prime numbers from 0-100 ''' ## Code Here - +j = 2 +while j < 100: + k = 2 + while k < j: + z = j - k + if j % k == 0: + break + if z == 1: + print(j) + k=k+1 + j = j + 1 ''' Problem - 2 Print the reverse of a string ''' string = 'Reverse Me!' ## Code Here +rev = '' +for i in string: + rev=i+rev +print(rev) diff --git a/Week1/work.py b/Week1/work.py index 9c53179..1cdaf9d 100644 --- a/Week1/work.py +++ b/Week1/work.py @@ -12,8 +12,9 @@ def demo(x): ''' ## Code Here - return None - + return x*x +#y=6 +#print (demo(9)) def is_palindrome(string): ''' This function returns True if the given string is @@ -25,8 +26,17 @@ def is_palindrome(string): ''' ## Code Here - return None + for i in range(0,len(string)): + if string[i] != string[len(string)-i-1]: + return 0 + + + return 1 +''' +s1='n mam n' +print(is_palindrome(s1)) +''' def sqrt_of_numbers(num): ''' This function returns the magnitude of the square root of the number @@ -35,10 +45,10 @@ def sqrt_of_numbers(num): returns: sqroot (float) ''' - + s=math.sqrt(num) ## Code Here - return None - + return s +#print (sqrt_of_numbers(101)) def Maximum(arr): ''' This function returns first maximum and the second maximum @@ -48,10 +58,21 @@ def Maximum(arr): returns: Max1, Max2 (int, int) ''' + # numpy.zeros(shape, dtype=float, order='C', *, like=None)ΒΆ - ## Code Here - return None + y=arr[0] + z=y + for i in arr: + if i>y: + z=y + y=i + + + ## Code Here + return y,z +#arr=[1,4,5,6,777,9999] +#print(Maximum(arr)) def even_sort(arr): ''' This function sorts the array giving higher preference to even numbers @@ -65,12 +86,27 @@ def even_sort(arr): sort_arr = [2, 6, 88 ,7 ,15] ## This is any even number is smaller than any odd number ''' + a1=[] + a2=[] + for i in arr: + if(i%2==0): + a1.append(i) + + else: + a2.append(i) + + a1.sort() + a2.sort() + ## np.concatenate((a1,a2),axis=0) ## Code Here - return None + return (a1+a2) +# a=a.append([i]) +#arr=[0,1,2,4,6,3,234324,34] +#print( even_sort(arr)) -def eqn_solver(A, B, C): +def eqn_solver(a, b, c): ''' This function solves a two variable system i.e., @@ -86,6 +122,13 @@ def eqn_solver(A, B, C): returns: x, y (float, float) ''' - + x=(c[0]*b[1]-b[0]*c[1])/(a[0]*b[1]-a[1]*b[0]) + y=(a[0]*c[1]-a[1]*c[0])/(a[0]*b[1]-a[1]*b[0]) ## Code Here - return None + return x,y +''' +a=[12,2] +b=[3,-3] +c=[15,13] +print(eqn_solver(a, b, c)) +'''