Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"None" is being added at the bottom of the output

So whenever I run this code it outputs the values I need, but also a "None" value at the bottom
Why is that and how do I get rid of it?

insert = input("Insert Coin: ")

insert = int(insert)

amount_due = 50 - insert

def check_coins():
    if insert >= 0 and insert < 50:
        print("Amount Due:", amount_due)

    elif insert > 50:
        print(insert - 50)

    else:
        print("Amount Due:", amount_due)


print(check_coins())

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you are getting None because of printing the function call, and the function is returning None

print(check_coins())

You need not require the print along with the function call.

Can you try the following:

insert = input("Insert Coin: ")

insert = int(insert)

amount_due = 50 - insert

def check_coins():
    if insert >= 0 and insert < 50:
        print("Amount Due:", amount_due)

    elif insert > 50:
        print(insert - 50)

    else:
        print("Amount Due:", amount_due)


check_coins()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading