-4

I need to do this:

  • create the function named exampleThree, that will have three input parameters.
  • return the single string with element separated with ...

So for example, the text would need to go from: "I like dogs" ---> "I...like...dogs"

This is what I currently have but it is not working. It is telling me that a b and c "must be str, not int"

def exampleThree(a,b,c):
    return a + "..." + b + "..." + c

Can I get assistance with this? Thanks.

smac89
  • 39,374
  • 15
  • 132
  • 179
  • 2
    How did you call it? Your function is correct, but you're calling it incorrectly. – Tim Roberts Sep 02 '21 at 21:45
  • 4
    Better would be `return '...'.join((a,b,c))`. – Tim Roberts Sep 02 '21 at 21:46
  • As the error is telling you -- the function wants strings, and you're passing it ints. Did you try calling it as `exampleThree("I", "like", "dogs")` as in your example? – Samwise Sep 02 '21 at 21:47
  • Call the function with strings not ints as the error message is tell you – smac89 Sep 02 '21 at 21:48
  • just warp the variables with `str`: `str(a) + "...." + str(b) + "..." + str(c)` – tttony Sep 02 '21 at 21:48
  • thanks tttony, that worked! – JoeRoganFan69 Sep 02 '21 at 21:51
  • "It is telling me that a b and c "must be str, not int"" Well, what do you think that means? When you get an error message, the *first* thing you should do is *read it*. The second thing you should do is try to understand it. If you don't understand, first make sure you understand the individual words (use a dictionary if you need to), then just put some effort into thinking about it; if you're stuck, ask a clear question that's specific about why you're stuck. For example, if you're surprised that something is an int, explain why; if you don't know how to have a string instead, say that. – Karl Knechtel Sep 02 '21 at 22:31
  • And whatever result you get from that process, you should be [prepared to do some further research](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). – Karl Knechtel Sep 02 '21 at 22:32

2 Answers2

0

Python is not a strongly typed language, thus whatever you provide the function as parameters can be easily miss-typed.

S you have 2 options here:

  • specify the data type in the function signature
my_func(a:str, b:str, c:str):
    return a + "..." + b + "..." + c
  • cast parameters to str
my_func(a, b, c):
   return str(a) + "..." + str(b) + "..." + str(c)

the second option can result in exceptions if you try to cast objects

Diego Rodriguez
  • 368
  • 2
  • 9
0
#a function
def  exampleThree(a,b,c):
    return f"{a}....{b}....{c}"
# printing
print(exampleThree(25,30,40))

#an output
25....30....40
  • Welcome to Stack Overflow, and thank you for contributing an answer. Would you kindly edit your answer to to include an explanation of your code? That will help future readers better understand what is going on, and especially those members of the community who are new to the language and struggling to understand the concepts. – Jeremy Caney Sep 03 '21 at 03:05