def findTriplets(array, n): """ Description: :In thar define function as findTriplets parameters: :in that assign variables like (array,n) :initially i value start from zero.""" import logging from Functionslog import logger logger.setLevel(logging.INFO) try: for i in range(0, n - 2): for j in range(i + 1, n - 1): for k in range(j + 1, n): if array[i] + array[j] + array[k] == 0: #Any three values is equal to zero, here the condition True found = True logger.info(array[i]) logger.info(array[j]) logger.info(array[k]) except Exception as e: logger.info(e) # If no triplet with 0 sum # found in array if found == False: logger.info(" not exist ")
def CalculateDistance(x, y): """ description: :In that define function as CalculateDistance parameters: :we are assign two variables x and y :we define Math function.""" # calculating distance distance= math.sqrt(pow(x, 2)+pow(y, 2)) # print distance logger.info(distance)
def WindCalculation(Temperature, Speed): """ Description: :Here we define function as a WindCalculation Parameters: :in that assign variables like (Temperature and Speed) :thr input like in integer format return:Temperature, Speed.""" import logging from Functionslog import logger logger.setLevel(logging.INFO) try: # calculation part w = 35.74 + (0.6215 * Temperature) + ( (0.4275 * Temperature) - 35.75) * pow(Speed, 0.16) logger.info('calculated windchill is: ') logger.info(w) except Exception as e: logger.info("invalid", e)
def QuadraticCalculation(a, b, c): """ description: :in that define function as QuadraticCalculation parameters: :in that assign three variables like a, b and c :Here writing formula for (b.b-4ac) :we are import cMath function.""" import logging from Functionslog import logger logger.setLevel(logging.INFO) try: # Calculation delta = (b * b) - (4 * a * c) root1 = (-b + cmath.sqrt(delta)) / (2 * a) root2 = (-b - cmath.sqrt(delta)) / (2 * a) # printing value logger.info(root1) logger.info(root2) except Exception as e: logger.info(e)
def PrintArray(Rows, Columns): """ Description: :We are defining the function as PrintArray parameters: :in side passing two variables like Rows and Columns.""" array1 = [] print("Enter the entries row wise:") # For user input for i in range(Rows): # A for loop for row entries array2 = [] for j in range(Columns): # A for loop for column entries array2.append(input()) array1.append(array2) # For printing the array for i in range(Rows): for j in range(Columns): logger.info(array1[i]) logger.info(array[j]) logger.info()
description: :in that define function as QuadraticCalculation parameters: :in that assign three variables like a, b and c :Here writing formula for (b.b-4ac) :we are import cMath function.""" import logging from Functionslog import logger logger.setLevel(logging.INFO) try: # Calculation delta = (b * b) - (4 * a * c) root1 = (-b + cmath.sqrt(delta)) / (2 * a) root2 = (-b - cmath.sqrt(delta)) / (2 * a) # printing value logger.info(root1) logger.info(root2) except Exception as e: logger.info(e) try: # input values a = int(input('enter value of a: ')) b = int(input('enter value of b: ')) c = int(input('enter value of c: ')) QuadraticCalculation(a, b, c) except Exception as e: logger.info(e)
:Here we define function as a WindCalculation Parameters: :in that assign variables like (Temperature and Speed) :thr input like in integer format return:Temperature, Speed.""" import logging from Functionslog import logger logger.setLevel(logging.INFO) try: # calculation part w = 35.74 + (0.6215 * Temperature) + ( (0.4275 * Temperature) - 35.75) * pow(Speed, 0.16) logger.info('calculated windchill is: ') logger.info(w) except Exception as e: logger.info("invalid", e) def userinput(): Temperature = int( input('enter the value of temperature in Fahrenheit less then 50: ')) Speed = int(input('enter wind speed in miles per hour from 3 to 120: ')) return Temperature, Speed Temperature, Speed = userinput() if Speed > 120 or Speed < 3 or Temperature > 50: logger.info("Can't get WindChill at this Parameters") else: WindCalculation(Temperature, Speed)