How do I continue a def after calling a def inside the first? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I continue a def after calling a def inside the first?

I've nested a def inside a def and it works, but the first def doesn't continue afterwards. How do I make it continue where it left off after calling the second def? this is an example I've typed on since the original was typed on a computer https://code.sololearn.com/cOPNlS1Gi212/?ref=app

15th Sep 2017, 4:32 AM
Kai
16 Answers
+ 2
Why die you nest it? Why not make two separate defs.
15th Sep 2017, 4:38 AM
Paul
Paul - avatar
+ 2
..well.. shit hahaha thanks for trying to help though I at least learned something
15th Sep 2017, 5:06 AM
Kai
+ 2
you know what... I'm a moron. haha on the computer def Response and variable Response were both capitalized. I thought it didn't matter since one was a variable and the other was a def. I've learn so much hahahaha thanks a ton dude! epiphany from that last answer of yours 😂
15th Sep 2017, 5:11 AM
Kai
+ 1
I did, I'm currently typing an example since I did the original on a computer. But the 2 defs are orignally seperate. the second one calls the first one inside of it though as part of its events. I'll post the example soon
15th Sep 2017, 4:40 AM
Kai
+ 1
wait, what do you mean?
15th Sep 2017, 4:48 AM
Kai
+ 1
where at? I'm trying to be able to use this response def in multiple defs.. so the response variable needs to be cleared every time
15th Sep 2017, 4:51 AM
Kai
+ 1
for some reason that works on solo, but not on my computer... hahaha I'm running 3.6.2 if that matters
15th Sep 2017, 4:57 AM
Kai
+ 1
it says (response=Response () local variable 'response' referenced before assignment) I am able to input before adding that but it won't continue the outer def after the nested def completes
15th Sep 2017, 4:59 AM
Kai
+ 1
It is as if your IDE was case insensitive
15th Sep 2017, 5:07 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
a block is define by its indentation, so the code of a def inside a def is more indented than the code of the def
15th Sep 2017, 4:43 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
you did not save the return value of Reponse in Input :)
15th Sep 2017, 4:46 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
you should do : response = Reponse()
15th Sep 2017, 4:49 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
#It is exactly what the return statement is here for ! def Response(): response="" while response!='Y' and response != 'N': response=input('Y or N?').upper() print('def complete') return response def Intro(): print('can you hear me?') reponse = Response() if response=='Y': print('good') if response=='N': print('very funny')
15th Sep 2017, 4:53 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
What is the error message on your computer ?
15th Sep 2017, 4:58 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
I do not know what is the cause of that but it is not supposed to happen ! :o
15th Sep 2017, 5:06 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
Errors that make you feel like a moron happen sooo much, I know that feeling 😂 Glad to have been of help to you :)
15th Sep 2017, 5:34 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar