Reputation: 21
Google search, trial and error hasn't helped. Still fairly new to Python as well.
I want the function to run and print out options, and take the userInput
variable and use it in another function
def content(userInput):
options=[
'option 1',
'option 2
]
print '\n'.join(map(str, options))
userInput = raw_input("> ")
return userInput
content()
TypeError: content() takes exactly 1 argument (0 given)
Upvotes: 2
Views: 5895
Reputation: 3265
In the way you have defined this function, it needs to take userInput
as argument. Reading your code, it seems you don't really need this (you're overwriting userInput
instantly without using it), just do:
def content():
options=[
'option 1',
'option 2'
]
print '\n'.join(map(str, options))
userInput = raw_input("> ")
return userInput
content()
Upvotes: 0
Reputation: 4213
Currently I see no use of function argument userInput
to be used in your code as you are over riding it with raw_input
def content(): # if you are not willing to pass anything to function then you do not need to use anything as argument of function
options=['option 1', 'option 2']
print '\n'.join(map(str, options))
userInput = raw_input("> ") # whatever input you are passing in userInput as function argument will be overridden here
return userInput
content()
Upvotes: 1
Reputation: 4285
Your function,
def content(userInput):
options=[
'option 1',
'option 2
]
print '\n'.join(map(str, options))
userInput = raw_input("> ")
return userInput
content()
you provide an userInput
as an argument, but you executed the function without given any value of that argument i.e
content()
In python, when you provide any argument in a function, like you provided userInput
as an argument in your comment
function, python expect you to provide value of that userInput
argument and you did not provide it when you execute your function. Thats why its given you the error.
instead, you have to provide a value in place of your given argument like this(when executing the function)
content("any value")
or rewrite your code in this way,
def content(userInput=None):
.......
then you can execute it like this,
content()
NOTE: in your code, you did not use userInput
anywhere, so better you rewrite your code like this,
def content():
options=[
'option 1',
'option 2
]
print '\n'.join(map(str, options))
userInput = raw_input("> ")
return userInput
and then execute your function content
,
content()
Upvotes: 0
Reputation: 2924
You defined your function with parameter userInput
def content(userInput):
And in this case when you want to use it, you need to pass that parameter.
So where you have
content()
it should be more like
content(someVal)
or just in def content(userInput):
delete userInput
so it will be like:
def content():
Upvotes: 0