Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+4 votes

For question 2 on Routine Practice 11, I pass the first three test cases where it tests the whole program, but when it tests just the printFancyName function, it fails. The error reads:

Traceback (most recent call last):
File "source.py", line 23, in <module>
printFancyName('Jesse James')
NameError: name 'printFancyName' is not defined

For reference, I have defined that function just inside my main function. I'm not sure why it's giving me an error.

asked in CSC201 Spring 2021 by (1 point)

2 Answers

+3 votes
 
Best answer

I think you should define that function outside of the main function with one parameter 'name' You just need to call the printFancyName inside the main function. For example: printFancyName('Jesse James')

answered by (1 point)
selected by
0

Thank you! That was my problem, I put the printFancyName function inside my main function, instead of having them separate. Thank you!

+2 votes

You don't need to pass in the name as a parameter. Your parameter will be the variable that takes input from the user. So you will need to make an input statement in def main
I hope that helps

answered by (1 point)
+1

I have an input statement that takes a variable name from the user. It appears that this specific test case does not use that, however. Like I said, when the test case Moodle used utilized my whole code, it worked fine. The case that failed appears to only use the printFancyName definition from my code, rather than the whole code. I'm not sure how it works. I didn't modify that portion of the code from number 1, other than putting it inside the main function.

...