Strings in functions


#1



Hey guys I am stuck on exercise 7 on function recap, any help will be really appreciated


This is the error,

File "python", line 2
string_function(s):
^
SyntaxError: invalid syntax

I don't understand why the syntax is wrong

n = "Hello"
string_function(s):
    return s + "world"



print string_function(n).


#2

a function should start with a def keyword:

def example():
    return "i am a function"

your def keyword is missing


#3
n = "Hello"

def string_function(s):
   s = "world"
   return s


print n + string_function(n)

Got error " Oops, try again. string_function('Hello') returned 'world' instead of 'Helloworld'
What's wrong with my code?


#4

you update s to "world" while you should join them (s + "world") together with a + and then return it


#5

Of course sorry silly error, thanks anyways


#6

Yes you assign s to 'world'.. but this is a stupid, buggy exersice! It told me to write 'Helloworld', first i printet 'helloworld', wrong, then 'Helloworld', then it said THAT was wrong, because i should write 'Waynesworld', because apparently s was assigned to be Wayne, so when i made the code
n = 'Hello'
def string_funtion(s):
return (s + 'world')
print string_function(n)
This does write 'Helloworld', even though it just said i returned Helloworld (which it asked me to do!) it even wrote string_function(Waynes)
Btw, returning n + s gives the correct 'Helloworld', but it still says error, i hate this site, so many ■■■■ bugs!


#7

n = "Hello"

Your function here!

def string_function(s):
s = "world"
return n + s

print(string_function(n))

Oops, try again. string_function('Waynes') returned 'Helloworld' instead of 'Waynesworld'

WTF????


#8

I have the same problem. This isn't the first time this has happened. I'm not sure what the incentive is to 'go pro' when you cant even finish one of their exercises...


#9

@bentleys550 instead of def string_function(s) try def string_function(n) ....that should work.