-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.

8
  • 2
    How did you call it? Your function is correct, but you're calling it incorrectly. Commented Sep 2, 2021 at 21:45
  • 4
    Better would be return '...'.join((a,b,c)). Commented Sep 2, 2021 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? Commented Sep 2, 2021 at 21:47
  • Call the function with strings not ints as the error message is tell you Commented Sep 2, 2021 at 21:48
  • just warp the variables with str: str(a) + "...." + str(b) + "..." + str(c) Commented Sep 2, 2021 at 21:48

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

The first option has literally no effect unless you run your code through a typechecker like mypy.
0
#a function
def  exampleThree(a,b,c):
    return f"{a}....{b}....{c}"
# printing
print(exampleThree(25,30,40))

#an output
25....30....40

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.