Nested Functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Nested Functions

So I'm having trouble understanding what I ccan and can't do in python cause I started learning this week but I'm having 2 main problems with my code posted here: https://code.sololearn.com/c5k8I61wO7YF/#py For starters, my if statement always works and it shouldn't when 'a' 's' 'd' or 'm' is entered And lastly, I'm trying to concatenate user input with a function to create a custom call that the user "technically" does themselves. For an example, 'a' is typed then a is inserted into a function and returned as the output of the function as, a(num1, num2) outputting 7 (3 = num1, 4 = num2)

13th Jun 2019, 3:50 PM
Evan Martine
3 Answers
+ 1
You shouldn't define functions within an 'if' block. Functions should be defined outside of other code blocks so, in your case and in the majority of cases, at or near the start of your code (before your while True statement). Edit: modifed code: https://code.sololearn.com/cJWAX6NxkIkf/?ref=app
13th Jun 2019, 4:23 PM
Russ
Russ - avatar
+ 1
No problem. Glad to help. I don't think this particular use of dictionaries is taught in the lessons but it's something I've picked up trying to solve similar problems.
13th Jun 2019, 6:00 PM
Russ
Russ - avatar
0
Russ Thanks for the help. I had no idea about these dictionary things. Must be a later lesson
13th Jun 2019, 4:48 PM
Evan Martine