Issue 2551031
Created on 2019-03-15 10:36 by When in trouble, go to the library, last changed 2019-03-26 19:45 by schlatterbeck.
Messages | |||
---|---|---|---|
msg6396 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-15 10:36 | |
'''Funktion soll Funktionsobjekt f und Zahl n als Argumente entgegennehmen das Funktionsobjekt n-mal hintereinander ausführen''' def mach_n(f,n): if n <= 0: return else: f mach_n(f,n-1) f = beliebige_funktion # wild card for any function f def beliebige_funktion(): #define function f here Body #Test f=print_doof() def print_doof(): print('doof') RUN MODULE mach_n(f,6) RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py Traceback (most recent call last): File "C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py", line 13, in <module> f = beliebige_funktion # wild card for any function f NameError: name 'beliebige_funktion' is not defined >>> TYPE: SYNTAX |
|||
msg6397 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-15 10:40 | |
def mach_n(f,n): if n <= 0: return else: f mach_n(f,n-1) REMOVE WILD CARDS INTO COMMENTS AS TO NOT DISTURB THE CODE # f = beliebige_funktion wild card for any function f #define function f here #Test f=print_doof() def print_doof(): print('doof') mach_n(f,6) RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py Traceback (most recent call last): File "C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py", line 20, in <module> f=print_doof() NameError: name 'print_doof' is not defined >>> TYPE: SYNTAX |
|||
msg6398 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-15 10:45 | |
CHANGE INDENTION OF BODY 'print('doof')' #Test f=print_doof() def print_doof(): print('doof') mach_n(f,6) RUN MODULE Traceback (most recent call last): File "C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py", line 20, in <module> f=print_doof() NameError: name 'print_doof' is not defined >>> TYPE: SYNTAX HYPOTHESIS: I HAVE TO DEFINE THE FUNCTION BEFORE ASSIGNING IT TO F |
|||
msg6399 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-15 10:51 | |
TEST HYPOTHESIS: I HAVE TO DEFINE THE FUNCTION BEFORE ASSIGNING IT TO F #def beliebige_funktion(): define function f here # f = beliebige_funktion assign function f to f #Test f=print_doof() def print_doof(): print('doof') mach_n(f,6) RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py Traceback (most recent call last): File "C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py", line 19, in <module> f=print_doof() NameError: name 'print_doof' is not defined >>> TYPE: SYNTAX HYPOTHESIS: I FORGOT TO FIX THE ORDER OF DEFINITIONS WHEN ACTUALLY CALLING UP THE FUNCTION X) |
|||
msg6400 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-15 11:03 | |
DEFINE 'print_doof' BEFORE ASSIGNING IT TO f #def beliebige_funktion(): define function f here # f = beliebige_funktion assign function f to f #Test def print_doof(): print('doof') f=print_doof() mach_n(f,6) REREAD THE CODE CAREFULLY RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py doof >>> RESULT: RETUNRS 'doof' JUST ONCE ERROR MESSAGE: NONE -> TYPE: SEMANTICS/LOCIC BUG DESCRIPTION: PYTHON DOESN'T SEEM TO REALIZE IT'S SUPPOSED TO REPEAT mach_n(f,n) UNTIL n=0 -> THERE MUST BE SOMETHING WRONG WITH def mach_n(f,n): if n <= 0: return else: f mach_n(f,n-1) THAT IS NOT A SYNTAX ERROR PYTHON MUST HAVE UNDERSTOOD THE FOLLOWING PART OF THE DEFINITION def mach_n(f,n): if n <= 0: return else: f CORRECTLY, OTHERWISE IT COULDN'T HAVE RETURNED F -> THE PROBLEM MUST BE LOCATED IN THE LAST LINE OF THE BODY mach_n(f,n-1) |
|||
msg6409 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:04 | |
REVISING HYPOTHESIS THAT THE ERROR MUST BE LOCATED IN THE LAST LINE OF THE BODY mach_n(f,n-1) COMPILER COULD JUST HAVE EXECUTED f APPROACH: COMPARE def mach_n(f,n): if n <= 0: return else: f mach_n(f,n-1) TO ITS MODEL def print_n(s,n): if n <=0: return print (s) print_n(s,n-1) BY DOWNEY WHICH WORKS. IS THERE A DIFFERENCE WITHIN THE RESPECTIVE CODE? ANSWER: THERE IS NO else: IN def print_n(s,n):, THE CODE FOR n > 0 IS INDENTED LIKE else: WOULD HAVE BEEN, EXACTLY BELOW if -> NEXT STEP: ERASE else: IN def mach_n(f,n): INDENT f mach_n(f,n-1) LIKE print (s) print_n(s,n-1)IN def print_n(s,n): |
|||
msg6410 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:08 | |
def mach_n(f,n): if n <= 0: return f mach_n(f,n-1) #def beliebige_funktion(): define function f here # f = beliebige_funktion assign function f to f #Test def print_doof(): print('doof') f=print_doof() mach_n(f,6) RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py doof >>> DID I MISS SOMETHING IN COMPARING? |
|||
msg6411 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:13 | |
ANSWER: NO COULD PYTHON JUST HAVE EXECUTED print('doof')? SOLUTION: mach_n(print_doof,6) RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py doof >>> NO VISIBLE EFFECT |
|||
msg6412 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:17 | |
f=print_doof() mach_n(print_doof(),6) TRIED BY ADDING BRACES RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py doof doof >>> print_doof()IST JUST EXECUTED TWICE. PYTHON CLEARLY DOESN'T GET THE RECURSIVE COMMAND |
|||
msg6413 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:27 | |
MAYBE PYTHON JUST DOESN'T GET f IS SUPPOSED TO BE A FUNCTION LET'S TRY #def beliebige_funktion(): define function f here # f() = beliebige_funktion assign function f to f #Test def print_doof(): print('doof') f() = print_doof() def mach_n(f,n): if n <= 0: return f() mach_n(f,n-1) mach_n(f,6) RUN MODULE MESSAGE: SYNTAX ERROR. CAN'T ASSIGN f() = print_doof() TO FUNCTION CALL |
|||
msg6414 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:29 | |
THE BRACES ARE ACTUALLY NOT PART OF A FUNCTION'S NAME SO LET'S TRY REMOVING THEM def print_doof(): print('doof') f = print_doof def mach_n(f,n): if n <= 0: return f mach_n(f,n-1) mach_n(f,6) RUN MODULE RESTART: C:\Users\Henrike Schwenn\Roaming\Programs\Python\Python36\eigene Funktionen\rekursive Funktionen\mach_n mit Funktionsobjekt.py >>> PYTHON DOESN'T RETURN ANYTHING |
|||
msg6415 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:33 | |
TRY ADDING BRACES TO f IN ORDER TO SHOW THAT f IS THE NAME OF A FUNCTION; EVEN THOUGH THE BRACES ARE NOT PART OF THE FUNCTION'S NAME def print_doof(): print('doof') f() = print_doof def mach_n(f,n): if n <= 0: return f() mach_n(f,n-1) mach_n(f,6) RUN MODULE MESSAGE: SYNTAX ERROR. CAN'T ASSIGN f() = print_doof TO FUNCTION CALL |
|||
msg6416 | Author: [hidden] (When in trouble, go to the library) | Date: 2019-03-22 11:36 | |
NEXT STEP DEFINE f AS A FUNCTION def f(): f |
History | |||
---|---|---|---|
Date | User | Action | Args |
2019-03-26 19:45:39 | schlatterbeck | set | status: new -> closed nosy: - When in trouble, go to the library resolution: invalid |
2019-03-22 11:36:41 | When in trouble, go to the library | set | messages: + msg6416 |
2019-03-22 11:33:39 | When in trouble, go to the library | set | messages: + msg6415 |
2019-03-22 11:29:15 | When in trouble, go to the library | set | messages: + msg6414 |
2019-03-22 11:27:07 | When in trouble, go to the library | set | messages: + msg6413 |
2019-03-22 11:17:42 | When in trouble, go to the library | set | messages: + msg6412 |
2019-03-22 11:13:22 | When in trouble, go to the library | set | messages: + msg6411 |
2019-03-22 11:08:50 | When in trouble, go to the library | set | messages: + msg6410 |
2019-03-22 11:04:36 | When in trouble, go to the library | set | messages: + msg6409 |
2019-03-15 11:03:08 | When in trouble, go to the library | set | messages: + msg6400 |
2019-03-15 10:51:24 | When in trouble, go to the library | set | messages: + msg6399 |
2019-03-15 10:45:43 | When in trouble, go to the library | set | messages: + msg6398 |
2019-03-15 10:40:13 | When in trouble, go to the library | set | messages: + msg6397 |
2019-03-15 10:36:17 | When in trouble, go to the library | create |