Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basic strings and variables python

Write a function, called introduction(name, school) that takes, as input, a name (as a string) and a school, and returns the following text: “Hello. My name is name. I have always wanted to go to school.”

This is my code

def introduction("name","school"):
    return ("Hello.  My name is ") + str(name) + (".  I have always wanted to go to The") + str(school) + (".")

I'm getting this error:

Traceback (most recent call last):
  File "None", line 5, in <module>
invalid syntax: None, line 5, pos 23
like image 253
user2744489 Avatar asked Dec 11 '25 21:12

user2744489


1 Answers

def introduction("name","school"):

should be

def introduction(name,school):

The names you provide as the formal parameters of the function are essentially variables that the values of the actual parameters get assigned to. Including a literal value (like a string) wouldn't make much sense.

When you call or invoke the function, that is where you provide a real value (like a literal string)

def introduction(name,school):
    return ("Hello.  My name is ") + str(name) + (".  I have always wanted to go to The") + str(school) + (".")

print introduction("Brian","MIT")
like image 190
Brian Avatar answered Dec 13 '25 10:12

Brian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!