I am attempting the Testing Functions part of Futurecoder.io and I’m having some trouble with understanding and completing the task.
There are some rules to solve this equation:
- The body cannot include “+”
- I must use ‘surround’ instead
- Also it must start like this def alert(string, level)
I would be really grateful if you could help me with dissecting the problem below:
<code>def alert(string, level):
string = surround(string, ' ')
for _ in range(level):
string = surround(string, '!')
return string
print(alert('warning', 2))
</code>
<code>def alert(string, level):
string = surround(string, ' ')
for _ in range(level):
string = surround(string, '!')
return string
print(alert('warning', 2))
</code>
def alert(string, level):
string = surround(string, ' ')
for _ in range(level):
string = surround(string, '!')
return string
print(alert('warning', 2))
The output of this code should be:
<code>"!! Warning !!"
"!!!! DANGER !!!!"
</code>
<code>"!! Warning !!"
"!!!! DANGER !!!!"
</code>
"!! Warning !!"
"!!!! DANGER !!!!"
New contributor
Sleepy Llama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
To make it happen, you need to write surround
function.
<code>def surround(string, char):
return char + string + char
</code>
<code>def surround(string, char):
return char + string + char
</code>
def surround(string, char):
return char + string + char