0

I just started coding recently and did all my coding exercises within one file, so I want to organize it by making a code that tells me what function do I want to run. Here's the code:

    print('''choices:

dict
emojis
''')
run = input('What do you want to run? ')
funct = {
     'dict': 'dict()',
     'emojis': 'emojis_prog()'
}
output = ""
for prog in run:
    output = funct.get(prog, "That program does not exist!")
print(output)

edit: Ok so I have a python file that contains my short programming exercises and it's organized through def dict(): def emojis_prog(): def greet_user(name):. So I want to run these programs by making a code (within the same python file), where you specifically tell it what to run. So if I want to run the dict program, I would simply input here run = input('What do you want to run? ') dict and it would run that only

temporary
  • 1
  • 1
  • You don't have a clear question, but I guess you're seeking for modules and packages. – Masked Man Nov 21 '21 at 13:20
  • 1
    Note that `run` is a string, not a list, so your `for prog in run` loop will yield the individual letters in that string (almost certainly not what you want). – jarmod Nov 21 '21 at 13:23
  • Why not `'dict': dict(),` (or better yet, `'dict': dict`),rather than `'dict': 'dict()',`? That way the dictionary gives you the requested function invocation or the function itself rather than the name of the function. If you don't do something like that, your next Stack Overflow question is likely to be "how do I run a function given a string containing its name?" – John Coleman Nov 21 '21 at 13:24
  • 'dict': dict(), did not work – temporary Nov 21 '21 at 13:28
  • `'dict':dict()` wouldn't fix the bug that @jarmod pointed out -- that is a separate issue. – John Coleman Nov 21 '21 at 13:29

0 Answers0