Posts

 Prorgram is: # #           Equality elements lists, sets, dictionaries # Elem_A = 10 Elem_B = 10 Elem_C = 15 List_A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List_B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List_C = [1,2,3,3,3,6,7,8,9,10] Set_A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Set_B = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Set_C = {1, 2, 3, 3, 3, 3, 7, 8, 9, 10} Dictionary_A = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10} Dictionary_B = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10} Dictionary_C = {1:1, 2:2, 3:3, 4:3, 5:3, 6:3, 7:7, 8:8, 9:9, 10:10} def compare(X,Y):     if X == Y:         Alfa = True     else:         Alfa = False     return Alfa print(' Element equality') Elem_Test_AB = compare(Elem_A,Elem_B) print('Element A is equal to element B? Result is:', Elem_Test_AB) Elem_Test_AC = compare(Elem_A,Elem_C) print('Element A is equal to element C? Result is:', Elem_Test_AC) print(' List equality') List_Test_AB = compare(List_A,List_B) print('List A is

Data Validation. in PYTHON

Programe is: # #     Data validation #     x is a positive number #     y is the number in a set set SET #     z is a number in a range (a; b) #     w is less than A #     v is a number greater than A #     Function ispositive (x) return True if x is positive #     Function isinset (y) return True if y is a member in SET #     Function isinrange (z, a, b) return True if z <b and a <z #     Function isless (w, A) return True if w <A #     Function isgreather (v, B) return True if B <v def ispositive(x):     Beta = x.isdigit()     if Beta == True:         Gama = float(x)     else:         return False     if Gama > 0:         return True     else:         return false X1 = '10' print(ispositive(X1)) X2 = '-10' print(ispositive(X2)) # #  y is in set # def isinset(y, SET):     Alfa = False     for i in SET:         if i == y:             Alfa = True     return Alfa SET_1 = {1, 2, 3,4,5,6,7, 8, 9, 10} Y1 = 7 print(isinset(Y1, SET_1)) Y2 = 100 print(isinset(Y2,
Programe is: # #     Dynamic precision results printing # a =17 i = 0 answer = 'y' while answer == 'y' or answer =='Y':     alfa = input('decimal point is:')     FORMAT = " ' Result is:, '%." + alfa + "f'"     print('format is:', FORMAT)     print(FORMAT %a)     answer = input(' to continue type y or Y: ')     i = i +1 print(' Final running!', i, 'problems') Results are: Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license()" for more information. ======== RESTART: /Users/ionivan/Documents/Dynamic precisionPrinting.py ======== decimal point is:1 format is:  ' Result is:, '%.1f'  ' Result is:, '17.0'  to continue type y or Y: y decimal point is:2 format is:  ' Result is:, '%.2f'  ' Result is:, '17.00'  to con
Programe is:   # #   Function list and parameter list # def Function_1(Word):     print(' One parameter', Word)     return 1 def Function_2(Word):     Word1 = Word[0] + Word[1]     print(Word1)     return 2 def Function_3(Word):     Word2 = Word[0] + Word[1] + Word[2]     print(Word2)     return 3 functions = [Function_1, Function_2, Function_3] results = [0,0,0] WORD1 = "aaaa" WORD2 = "bbbb" WORD3 = "cccc" i = 0 parameters = [[WORD1], [WORD1,WORD2], [WORD1, WORD2, WORD3]] #parameters = ((WORD1), (WORD1,WORD2), (WORD1, WORD2, WORD3)) for ijj in (functions):     results[i] = ijj(parameters[i])     print (results[i], "\n")     i += 1 print(' Final running!') Results are: ========= RESTART: /Users/ionivan/Documents/ListFunctionParametersX.py =========  One parameter ['aaaa'] 1  aaaabbbb 2  aaaabbbbcccc 3   Final running! (April 02, 2022)

Functions than return a function

Programe is: # # Functions than return a function # def function_power(X, NR):     Y = X     for i in range(NR):         Y[i] *= X[i]     return function_add(Y,NR) def function_add(X,NR):     suma = 0     for i in range(NR):         suma += X[i]     return suma a = [1,2,3,4, 5] nr = len(a) b = function_power(a, nr) print("For list a = ", a,  " the sum of the squares of these elements:  ", b) Results are: ========== RESTART: /Users/ionivan/Documents/FunctionReturnFunction.py ========= For list a =  [1, 4, 9, 16, 25]  the sum of the squares of these elements:   55 (April 02, 2022)

Functions and return parameters list

 Program is: # #   functions and return parameters list # def function_1(a,b):     return [a+b] def function_2(a,b):     suma = a + b     if a > b:         minimum =b     else:         minimum = a     return [suma, minimum] def function_3(a,b):     suma = a + b     if a > b:         minimum = b     else:         minimum = a     if a > b:         maximum = a     else:         maximum = b     return [suma, minimum, maximum] X = 10 Y = 20 Z = function_1(X,Y) W = function_2(X,Y) A = function_3(X,Y) print(' If a=', X,  'and b= ', Y, 'than a+b=', Z[0]) print(' If a=', X,  'and b= ', Y, 'than a+b=', W[0], 'minumum is', W[1] ) print(' If a=', X,  'and b= ', Y, 'than a+b=', A[0], 'minumum is', A[1],       'and maximum is', A[2]) Results are: ============ RESTART: /Users/ionivan/Documents/FunctionReturnList.py ===========  If a= 10 and b=  20 than a+b= 30  If a= 10 and b=  20 than a+b= 30 min

Functions and many return parameters

Programe is:  # #   functions and many return parameters # def function_1(a,b):     return a+b def function_2(a,b):     suma = a + b     if a > b:         minimum =b     else:         minimum = a     return suma, minimum def function_3(a,b):     suma = a + b     if a > b:         minimum = b     else:         minimum = a     if a > b:         maximum = a     else:         maximum = b     return suma, minimum, maximum X = 10 Y = 20 Z = function_1(X,Y) W, V = function_2(X,Y) A, B, C = function_3(X,Y) print(' If a=', X,  'and b= ', Y, 'than a+b=', Z) print(' If a=', X,  'and b= ', Y, 'than a+b=', W, 'minumum is', V ) print(' If a=', X,  'and b= ', Y, 'than a+b=', A, 'minumum is', B,       'and maximum is', C)  Results are:  ============== RESTART: /Users/ionivan/Documents/FunctionReturn.py =============  If a= 10 and b=  20 than a+b= 30  If a= 10 and b=  20 than a+b= 30 minumum is 10