Python Forum
Lambda function not return value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lambda function not return value
#1
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 22 23:46:47 2020

@author: Lenovo
"""
import pdb
import unittest
import math

class Calculator:
    """
    A class is defined for calculator, to preform addition,subtration,multiplication,divison,power and exponent.
    """
    def __init__(self,num1,num2):
        try:
            assert type(num1) == int
            assert type(num2) == int
        except AssertionError:
            print('Invalid parameter type')
            raise Exception
        
        self.num1 = num1
        self.num2 = num2
        
        
    def addition(self):
        #pdb.set_trace()# we have added a breakpoint here. The code pause execution here.
        #print(' Addition')
        return (self.num1 + self.num2)
    def subtraction(self):
        return(self.num1 - self.num2)
    
    def division(self):
        return(self.num1 / self.num2)
    
    def moduler(self):
        return(self.num1 // self.num2)      
  
    def multiplication(self):
        return(self.num1 * self.num2)
        
    """def power(self):
        return(self.num1 ** self.num2)
       """ 
class ScientificCalculator(Calculator): #parent class refrence Calculator
    def __init__(self,num1,num2,number,exponent): #should be initialize this function __init__()
        super().__init__(num1,num2) # super() will refer paranent class variables
        self.number = number
        self.exponent = exponent
                
    def logg(self):
        #pdb.set_trace()  #we have added a breakpoint here. The code pause execution here.
        return math.log(self.number,self.exponent)

    def power(self):
        a = self.number
        b = self.exponent
        return lambda a,b:a**b

cal= Calculator(num1 = 2,num2 = 2)
print('addition',cal.addition())
sci_cal = ScientificCalculator(num1=1,num2=2,number = 2,exponent = 3)
print('log:',sci_cal.logg())
print('power:',sci_cal.power())
Output:
addition 4 log: 0.6309297535714574 power: <function ScientificCalculator.power.<locals>.<lambda> at 0x0000011660DFE798>
Reply


Messages In This Thread
Lambda function not return value - by mbilalshafiq - Jul-03-2020, 12:15 PM
RE: Lambda function not return value - by GOTO10 - Jul-03-2020, 01:57 PM
RE: Lambda function not return value - by ndc85430 - Jul-04-2020, 07:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of function/return Paulman 6 2,387 Oct-24-2021, 11:07 PM
Last Post: Paulman
  Multiple return from function Grimmar 7 3,591 Mar-22-2021, 09:20 PM
Last Post: Grimmar
  Child class function of Log return "None" mbilalshafiq 2 2,241 Jun-30-2020, 07:22 PM
Last Post: mbilalshafiq
  Question on "define function"; difference between return and print extricate 10 4,753 Jun-09-2020, 08:56 PM
Last Post: jefsummers
  [split] problem with function return value ops 1 3,369 Apr-13-2020, 01:48 PM
Last Post: buran
  Function to return today's month, day, and year sbabu 9 4,966 Jan-28-2020, 06:20 PM
Last Post: snippsat
  return outside function seamus 4 3,081 May-17-2019, 07:38 PM
Last Post: seamus
  Recursive Function - Compare 2 lists, return the elements that don't exist in both KellyBaptist 1 5,249 Dec-23-2018, 10:10 AM
Last Post: Gribouillis
  Need of return in function if statement inside the function already returns Athul 5 3,931 Aug-16-2018, 10:19 AM
Last Post: DuaneJack
  Calling function-- how to call simply return value, not whole process juliabrushett 2 3,232 Jul-01-2018, 01:17 AM
Last Post: juliabrushett

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020