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 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)
""" @date = '23/04/2021' @modified_date = '23/04/2021' @author = 'vishnu' @Title = 'Write a program Distance.py that takes two integer command-line arguments x and y and prints the Euclidean distance from the point (x, y) to the origin (0, 0). The formulae to calculate distance = sqrt(x*x + y*y). Use Math.power function' """ import math import logging from Functionslog import logger logger.setLevel(logging.INFO) 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) try: #taking inputs x and y x=int(input('enter x value: ')) y=int(input('enter y value: ')) CalculateDistance(x, y) except Exception as e: