function passing variables

Using python, How would I split this up to functions and call them?

fileName = input("Enter the filename: ")
f = open(fileName, ‘r’)
numbers =
for line in f:
words = line.split()
for word in words:


this one in a function

m = median(numbers)

this one in a function

md = mode(numbers)

print(“The media is %d” % (m))
print(“The mean is %d” % (md))

median(numbers) and mode(numbers) already are function calls. Could you explain what exactly you’re looking for? An explanation of how to define functions in Python, maybe?

Asso, when posting code you should wrap it in triple backticks (```) or use the code button (with the </> symbol), that way it stays indented as it should be. Which is particularly important with Python, but makes the code much more readable with any language. :wink: