I'm getting None with output. HOW TO FIX IT ? seems the issue with the two print statements. However, unable to fix the issue, could I have the resolution to fix this

class RBI:
def Interest(self):
pass
class SBI(RBI):
def Interest(self):
print(“SBI FD interest rates are 5.1%”)
class PNB(RBI):
def Interest(self):
print(“PNB FD interest rates are 5.1%”)
S= SBI()
P= PNB()
print(S.Interest())
print(P.Interest())

OUTPUT:
SBI FD interest rates are 5.1%
None
PNB FD interest rates are 5.1%
None

(post deleted by author)

By Chandan Singh via Discussions on Python.org at 14Apr2022 00:19:

class RBI:
def Interest(self):
pass
class SBI(RBI):
def Interest(self):
print(“SBI FD interest rates are 5.1%”)
class PNB(RBI):
def Interest(self):
print(“PNB FD interest rates are 5.1%”)
S= SBI()
P= PNB()
print(S.Interest())
print(P.Interest())

OUTPUT:
SBI FD interest rates are 5.1%
None
PNB FD interest rates are 5.1%
None

I assume the above is at the interactive >>> prompt?

The reason is that “print()” does not return a value from a function. It
just writes some text, usually to your screen.

The interactive prompt prints the value of the last expression you
typed. So:

>>> 3
3

A function with no return statement still returns a value, it is just
the value None.

So if your run looked like this:

print(S.Interest())
SBI FD interest rates are 5.1%
None

That is because the SBI.Interest method printed “SBI FD interest
rates are 5.1%” and returned None. You prompt want it to look like
this:

class SBI(RBI):
    def Interest(self):
        print("SBI FD interest rates are 5.1%")
        return 5.1

or even more typically:

class SBI(RBI):
    def Interest(self):
        return 5.1

which you might use like this:

>>> interest = S.Interest()
>>> print(interest)
5.1

Actually, on reflection, the usual >>> interactive prompt quietly
prints nothing if the return value is None, so maybe you’re using
something else. But the situation is the same. Your function was not
returning a value, so it returned None (the default).

Cheers,
Cameron Simpson cs@cskk.id.au

By Cameron Simpson via Discussions on Python.org at 14Apr2022 03:26:

print(S.Interest())
print(P.Interest())

OUTPUT:
SBI FD interest rates are 5.1%
None
PNB FD interest rates are 5.1%
None

Ah, I have rethought this. All the stuff about return still holds.

So you call S.Interest() and it prints the interest rate message.

But you called it from iside this:

print(S.Interest())

which prints the return value from S.Interest(), and that return value
is None because the method has no explicit return statement.

So you get a print() during the function, and the second print above.

Cheers,
Cameron Simpson cs@cskk.id.au

Thank you so much !!!

Tried with S.Interest() and P.Interest(). It worked …!!

Personally, I would make the Interest methods just return the interest rate, and do the print outside:

def Interest(self):
    return 5.1

then:

Si = SBI.Interest()
print(f"SBI FD Interest rates are {Si}%")

which lets you use the value in Si in calculations.

Cheers,
Cameron Simpson