logo CodeStepByStep logo

write_chars

Language/Type: Python recursion recursive programming

Write a recursive function named write_chars that accepts an integer parameter n and that prints out a total of n characters. The middle character of the output should always be an asterisk ("*"). If you are asked to write out an even number of characters, then there will be two asterisks in the middle ("**"). Before the asterisk(s) you should write out less-than characters ("<"). After the asterisk(s) you should write out greater-than characters (">"). Your function should raise a ValueError if it is passed a value less than 1. For example, the following calls produce the following output:

Call Output
write_chars(1) *
write_chars(2) **
write_chars(3) <*>
write_chars(4) <**>
write_chars(5) <<*>>
write_chars(6) <<**>>
write_chars(7) <<<*>>>
write_chars(8) <<<**>>>
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.