Python Forum
Class method returning multiple values,dont know which is returned when..
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class method returning multiple values,dont know which is returned when..
#1
Dear all, Good morning from Germany,
I have a python code in which the function returns two values. Out of which, only one value changes at a time and other remains the same. I want to find which is changing and want to append it. The code looks as following
def calcrand(self,xlowrand,xhighrand):
        xalg = self.xalg
        yalg = self.yalg
        xlowrand = self.xlowrand
        xhighrand = self.xhighrand
                        
        if (len(xalg))>=2 and len(yalg)>=2:
            last = len(yalg)-1
            xPrevious = xalg[last-1]
            xLast = xalg[last]    
            yPrevious = yalg[last-1]
            yLast = yalg[last]
            prevdist= abs(yalg[last-1]-ygoal)
            currentdist= abs(yalg[last]-ygoal)
                                                          
            if currentdist<prevdist:
                m=float ((yLast-yPrevious)/(xLast-xPrevious)) 
                
                if m>0:
                    if yalg[last]< ygoal:
                        xlowrand=xalg[last]
                        return float(xlowrand),float(xhighrand),
                    else:
                        xhighrand=xalg[last]
                        return float(xlowrand),float(xhighrand)
                elif yalg[last]< ygoal:
                    xhighrand=xalg[last]
                    return float(xlowrand),float(xhighrand)
                else:
                    xlowrand=xalg[last]
                    return float(xlowrand),float(xhighrand)              
                                         
        elif (len(xalg))==1:
            return float(xlowrand),float(xhighrand)
    
        elif (len(xalg))<1:
            return float(xlowrand),float(xhighrand)

        else:
            print('there are no data')
            
        return float(xlowrand),float(xhighrand)
I run this in a loop...
Reply


Messages In This Thread
Class method returning multiple values,dont know which is returned when.. - by ujjwalrathod007 - Sep-29-2016, 09:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Method returning None husksedgier 2 176 May-04-2024, 06:38 PM
Last Post: husksedgier
  class definition and problem with a method HerrAyas 2 298 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Printing out incidence values for Class Object SquderDragon 3 323 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  super() and order of running method in class inheritance akbarza 7 826 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  __init__() got multiple values for argument 'schema' dawid294 4 2,550 Jan-03-2024, 09:42 AM
Last Post: buran
  How to access values returned from inquirer cspower 6 889 Dec-26-2023, 09:34 PM
Last Post: cspower
  Can I use logging in a class (without multiple messages) mevan 2 622 Oct-16-2023, 11:08 PM
Last Post: mevan
  Code is returning the incorrect values. syntax error 007sonic 6 1,269 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Using one child class method in another child class garynewport 5 1,669 Jan-11-2023, 06:07 PM
Last Post: garynewport
  I dont know why my function won't work? MehHz2526 3 1,216 Nov-28-2022, 09:32 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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