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

unsupported operand type(s) for *: 'NoneType' and 'NoneType'

def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
    d = d.replace('$', '')
    d = float(d)
    print(d)
def percent_to_float(p):
    p = p.replace('%', '')
    p = float(p)
    p = p/100
    print(p)

main()

tried to convert "dollars" and "percent" but it didn’t work, I searched but most of the things didn’t work and i didn’t understand some because I’m new to python

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

>Solution :

You aren’t returning anything from your functions. If you want a value returned, then you must do so. Use return p instead of print(p). Utility functions should not PRINT their results. They should RETURN their results and let the caller decide what to do with it.

def dollars_to_float(d):
    d = d.replace('$', '')
    d = float(d)
    return d
def percent_to_float(p):
    p = p.replace('%', '')
    p = float(p)
    p = p/100
    return p
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