简体   繁体   中英

Python code returns “None”

def average(numbers):
    total = float(sum(numbers))
    total /= len(numbers)
    return

Error: Oops, try again.

average([3, 0]) returned None instead of 1.5 as expected.

What is wrong pls?

You are not returning any value.

Try this instead:

def average(numbers): 
    total = float(sum(numbers)) 
    total /= len(numbers) 
    return total

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM