Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Child class function of Log return "None"
#1
# what is an issue in below coding , when i call child class function is return "None", Please guide us. #Thanks...

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.
        math.log(self.number,self.exponent)


cal= Calculator(num1 = 2,num2 = 2)
print('addition',cal.addition())
sci_cal = ScientificCalculator(num1=1,num2=2,number = 100,exponent = 3)
print('log:',sci_cal.logg())
--------------------------------

Out Put:

Output:
addition 4 log: None
Yoriz wrote Jun-30-2020, 06:28 PM:
Please post all code, output and errors (in its entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
def logg(self):
        #pdb.set_trace()  #we have added a breakpoint here. The code pause execution here.
        math.log(self.number,self.exponent)
the method logg is not returning anything so it defaults to return None

Add in a return as follows
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)
Quote
#3
Thanks dear for your guidance. Now my function is return value.
Yoriz likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Lambda function not return value mbilalshafiq 4 134 Jul-04-2020, 07:47 AM
Last Post: ndc85430
  Question on "define function"; difference between return and print extricate 10 359 Jun-09-2020, 08:56 PM
Last Post: jefsummers
  [split] problem with function return value ops 1 202 Apr-13-2020, 01:48 PM
Last Post: buran
  How can you add an attribute to a function within a class? sjaakthomassen 2 228 Mar-18-2020, 12:27 AM
Last Post: scidam
  Function to return today's month, day, and year sbabu 9 521 Jan-28-2020, 06:20 PM
Last Post: snippsat
  Child Class, Loop list bjornnotborg 2 480 Aug-28-2019, 12:31 PM
Last Post: bjornnotborg
  return outside function seamus 4 651 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 1,102 Dec-23-2018, 10:10 AM
Last Post: Gribouillis
  Need of return in function if statement inside the function already returns Athul 5 1,344 Aug-16-2018, 10:19 AM
Last Post: DuaneJack
  Calling function-- how to call simply return value, not whole process juliabrushett 2 1,089 Jul-01-2018, 01:17 AM
Last Post: juliabrushett

Forum Jump:


Users browsing this thread: 1 Guest(s)