Reputation: 1
Write a function named evenOddString()
that takes a single string parameter.
If the length of the string parameter:
evenOddString()
should return the string parameter.evenOddString()
should return the string parameter concatenated with itself.This is my code so far:
def evenOddString():
len(var) % 2 != 0
Upvotes: 0
Views: 6703
Reputation: 29942
def control4OddString(myString):
if len(myString) % 2: return myString
else: return myString+myString
Upvotes: 0
Reputation: 2629
First, your evenOddString() function needs to take a parameter. For example:
def evenOddString(the_string_parameter):
print(the_string_parameter)
To call that function, you would have something like:
evenOddString('abc123')
which would print out abc123 on the console. In your case, you will want check the length of the_string_parameter and do some stuff with it "if" the length is even or odd. The if and elif statements will be helpful. See http://docs.python.org/tutorial/controlflow.html for docs on flow control.
You also want to return a value back out of your function. If I wanted to return the string unchanged, I would do something like:
def evenOddString(the_string_parameter):
return the_string_parameter
Note that I'm being a little vague here as this sounds like a homework assignment and I don't want to simply write all the code for you. Since you sound like a new programmer just starting out and in need of a good tutorial, I highly recommend you work through http://learnpythonthehardway.org/
Upvotes: 3
Reputation: 114035
Upvotes: 2