Posts

Functions list in PYTHON

Programe is: # #    Functions list # def print_1(Word,val):  #  print string function     Alfa = Word[val-1]     print(Alfa)     return  def sum_x(x,nr):   # add list elements function     s =0     for i in range(nr):         s+= x[i]     return s def norma_a(a,nr):  # add absolute value list elements function     norm = 0     for i in range(nr):         norm += abs(a[i])     return norm functions = [print_1, sum_x, norma_a]    # functions list results = [0,0,0] WORD = ["aaaa", "bbbb", "cccc", "dddd","eeee",         "ffff", "gggg", "hhhh", "mmmm","nnnn"] X = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] A = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10] NR = [10, 10, 10] NRR =3 i = 0 parameters = [WORD, X, A] for ijj in (functions):     results[i] = ijj(parameters[i], NR[i])     print (results[...

PYTHON and variables?

 PYTON does not work with variables. PYTON works with: - name, - objects, - types, - values, - reference number. If we write: a = 7 then: - a is the name - a PYTHON object corresponding to the name a is created - 7 is value - the type is whole - the reference count is 0. if we write below a = 100 then: - remain the same name, - a new object associated with the name a is created, - the type is integer, - the reference count is 1 This explains the different addresses id (a) from the first assignment and from the second assignment. Programe is: a = 7 print(id(a)) a = 100 print(id(a)) Results are: ============== RESTART: /Users/ionivan/Documents/pointerspython.py ============= 4408295856 4408298832 If the sequence is considered: a = 25 b = a the names a and b correspond to the same object, so they will have the same address. Programul este: a = 25 b = a print("Adress a name is",id(a)) print("Adress b name is",id(b)) Rezultatele sunt: ============== RESTART: /Users/ioniv...

Pointers in PYTHON?

 Memory programming is used in programming. A memory area is defined by: - associated variable name, - length as number of bytes, - address of the first byte, - content as a string of bits with contextual interpretation. The contents of the pointer variable are the address of a memory area. A variable is referred to when its address is loaded into a pointer variable. A pointer variable is redirected using its contents to reach the contents of the variable whose address it contains. The reference operator initializes the pointer variable. The pointer referral operator provides the contents of the memory area whose address it contains. And the PYTHON language natural works with pointer variables. PYTHON works differently and spectacular with pointers. (March 31, 2022)

Quadratic equation solutions programe

Programe is: # #  Quadratic equation solutions programe #  a*x**2 + b*x + c = 0 # import cmath answer = 'y' while answer == 'y' or answer == 'Y':     a = float(input(' coeficient a is:'))     b = float(input(' coeficient b is:'))     c = float(input(' coeficient c is:'))     gama = 2*a     eta = -b/gama     delta = cmath.sqrt(b*b - 4*a*c)/gama     x_1 = eta - delta     x_2 = eta + delta     print('The solution X1 is:', x_1)     print('The solution X2 is:', x_2)     answer = input(' If you want to continue, type y or Y: ') print(' Thank you for working with this program!') Results are: ============ RESTART: /Users/ionivan/Documents/QuadraticEcuation.py ============  coeficient a is:1  coeficient b is:1  coeficient c is:1 The solution X1 is: (-0.5-0.8660254037844386j) The solution X2 is: (-0.5+0.8660254037844386j)  If you want to continue, type y or Y...

exp(A), A is a matrix

Programe is: # # Calculate A**n, A is a matrix,  n is an integer #                 A has maximum 15 rows and 15 columns # AA =  [[1,2,3,4],       [2,3,4,5],       [3,4,5,6],       [4,5,6,7]] AAA = [[2,2],       [2,2]] BB =  [[1,1,1,1],       [1,1,1,1],       [1,1,1,1],       [2,2,2,2]] NN_row = 4 NN_column = 4 def product_AB(A, B, N_row, N_column):     C =  [[1,1,1,1],       [1,1,1,1],       [1,1,1,1],       [2,2,2,2]]    # C = [[0]*N_row]*N_column     for i in range(N_row):         for j in range(N_column):             C[i][j]=0             for k in range(N_column):                 C[i][j] += A[i][k]*B[k][j]     retur...

PYTHON comments

 All programmers use program comments. Comments: - shows the significance of the variables, - clarification of the sequences, - state what restrictions must be observed, - specify the date when the program was written, - say who the author of the program is, - define the bibliography used, - helps in the maintenance process. Comments are written as follows: # short comment "" "on the start line of the comment and on the" "" end line of the comment. speed = [1, 2, 3, 4, 5] # speed list A_square = 25 # area of the square for i range (#): # gathers the elements of the X_list      sum + = X_list [i] "" " The program is written on March 30, 2022 The BELMAN KALABA algorithm is used The author is Ion IVAN "" " Including comments in programs is called self-documenting. (March 30, 2022)

lambda keyword usage in PYTHON programe

Programe is: # #       lambda option usage în PYTHON programe #       only one parameter restriction limits the structures #       geometry problems exemples #        A_circle = area of the circle #        L_cilcre = the length of the circle #        A_ square = area of the square #        P_square = square perimeter #        R = radius of the circle #        L = the side of the square of the triangle #        H = height #        P_triangle = the perimeter of the equilateral triangle #        A_triangle = area of the equilateral triangle #        V_cube = volume of the cube #        A_cube = total cube area #        A_sphere = area of the sphere #        V_sphere = volume ...