-1

When I try to run module the output shows "None". What can I change for my function. Like this: Enter a set of numbers separated by spaces for analysis: 10 2 38 23 38 23 21 23 None

import math
def get_numbers():
        numbers_string = input("Enter a set of numbers separated by spaces for analysis: ")
        numbers = numbers_string.split()
        for index in range(len(numbers)):
                numbers[index] = int(numbers[index])                
        numbers.sort()
print(get_numbers())

output: Enter a set of numbers separated by spaces for analysis: 10 2 38 23

    38     23     21 23
[10, 2, 38, 23, 38, 23, 21, 23]
Rakesh
  • 81,458
  • 17
  • 76
  • 113
Christina
  • 27
  • 2
  • 5
  • 3
    Just add `return numbers` at the end of the function, to, well, you guessed it, return the numbers. – tobias_k Aug 06 '19 at 11:31
  • Possible duplicate of [Function returns None without return statement](https://stackoverflow.com/questions/7053652/function-returns-none-without-return-statement) – Tomerikoo Aug 06 '19 at 11:44

2 Answers2

0

Nothing is being returned in your function. Just add return numbers at the end of function and it will work.

0

Example:

def get_numbers():
        numbers_string = input("Enter a set of numbers separated by spaces for analysis: ")
        numbers = list(map(int, numbers_string.split()))
        numbers.sort()
        return numbers

print(get_numbers())

Output:

>>> python3 test.py 
Enter a set of numbers separated by spaces for analysis: 3 6 8 5 4
[3, 4, 5, 6, 8]
milanbalazs
  • 4,811
  • 4
  • 23
  • 45