How do i get this error hes talking about heres my code. def printTwice(bruce): print bruce, bruce def catTwice(part1, part2): cat = part1 + part2 printTwice(cat) chant1 = "Pie Jesu domine, " chant2 = "Dona eis requiem." catTwice(chant1, chant2) If an error occurs during a function call, Python prints the name of the function, and the name of the function that called it, and the name of the function that called that, all the way back to __main__. For example, if we try to access cat from within printTwice, we get a NameError: Traceback (innermost last): Fil
For example, if we try to access cat from within printTwice, we get a NameError: Traceback (innermost last): File "test.py", line 13, in __main__ catTwice(chant1, chant2) File "test.py", line 5, in catTwice printTwice(cat) File "test.py", line 9, in printTwice print cat NameError: cat
I think he means something like this: def printTwice(bruce): print cat, cat def catTwice(part1, part2): cat = part1 + part2 printTwice(cat) You can't refer to "cat" from printTwice() because it's defined in another function. (Actually, there's just nothing called "cat" that's accessible from the scope inside of printTwice(). You'd get the same error if you tried "print foo, foo" because there's no "foo" variable, either.)
Join our real-time social learning platform and learn together with your friends!