-2

I'm trying to make a script to both teach my friend what little Python knowledge I have, and to refresh my own memory. I just started and it isn't finished at all either, but when I test run it, nothing happens. How do I run functions?

Here is my current code so far:

def mainmenu():
    choice = {
        'print',
        'comments',
        'if',
        'else',
        'and',
        'or',
        'elif',
        'input',
        'variables',
        'strings',
        'def',
        'class',
        'modules',
        }
    print("What would you like to learn about?")
    for statement in choice():
        print("- Type {} to learn about {}".format(statement))
    pclass = input(">>>")
    if pclass in choice():
        return choice[pclass]()
    else:
    print("Invalid Choice")

Also in my for statement in choice I'm trying to make it repeat the print thing for every string in the set; I'm aware statement probably isn't even in the spectrum of what I need to type for it to do that. Any idea on what I should replace that with?

Armali
  • 18,255
  • 14
  • 57
  • 171
xXMAZEEXx
  • 13
  • 5

1 Answers1

1

That script have some flaws (see below), and you would call a function in Python by just calling it after the function is defined with open-close parenthesis (if there are no arguments passed). Somewhat working code would be:

def mainmenu():
choice = {
    'print',
    'comments',
    'if',
    'else',
    'and',
    'or',
    'elif',
    'input',
    'variables',
    'strings',
    'def',
    'class',
    'modules',
    }
print("What would you like to learn about?")
for statement in choice:
    print("- Type {} to learn about {}".format(statement, statement))
pclass = input(">>>")
if pclass in choice:
    return pclass
else:
    print("Invalid Choice")

mainmenu()
sla3k
  • 209
  • 1
  • 4