0

I'm trying to make optional importing a module, but I'm not able to rewrite the code in an easier way (it works like this):

import sys
sys.path.append('\python_work\chemistry\import')

prompt = "Would you like to check if calculus worked as it should? (yes/no) "
if prompt == 'yes':
    import normal_termination
elif prompt == 'no':
    # pale_green + end are from a colouring module
    print(pale_green + "Skipping to the next step" + end)
else:
    active = True
    while active:
        message = input(prompt)

        if message == 'yes':
            active = False
            import normal_termination
        elif message == 'no':
            active == False
            print(pale_green + "Skipping to the next step" + end)
            break

I tried many different things but nothing works. What I want it to do is: Ask a simple question. If answer = yes -> import; If answer = no -> print(message); If answer != yes, answer != no, repeat the user input.

martineau
  • 119,623
  • 25
  • 170
  • 301
Gabri
  • 3
  • 2
  • What do you mean "in a proper way"? If it works then what else do you need? – user32882 Aug 24 '20 at 16:13
  • Regarding the "proper way" as another commentator has pointed out, in Python community people often ask "what is the pythonic way." This is just a matter of community culture, but helps with the communication. – Raiyan Aug 24 '20 at 16:19

1 Answers1

0

Maybe something like this:

import sys
sys.path.append('\python_work\chemistry\import')

prompt = ''
while prompt != 'yes' and prompt != 'no':
    prompt = input("Would you like to check if calculus worked as it should? (yes/no) ")
    if prompt == 'yes':
        import normal_termination
    elif prompt == 'no':
        print("Skipping to the next step")
Ktoto
  • 91
  • 6