-1

Everybody.

I'm making a software to crawl webpage and bring some information.

In the beginning I ask 3 questions like:

    print('What tipe of information you want?')
    print('1. Basic Information (Title, Description, No Index and Canonical);\n2. See the whole visible text;\n3. See top 10 words')
    print()
    resposta = input('Insert only number: ')

All 3 are running with:

if resposta == '2':
    print(output)

if resposta == '3':
    print('Top 10 keywords are:')
    print(top)

What I want to do is:

After the user input a number, I want to ask a question in loop, like:

Do you want any more information? Y or N

If he types Yes the codes brings him to the first question:

    print('What tipe of information you want?')
    print('1. Basic Information (Title, Description, No Index and Canonical);\n2. See the whole visible text;\n3. See top 10 words')
    print()
    resposta = input('Insert only number: ')

If he types "N" I print: thanks, see ya. And the program closes.

Would be glad if anyone could help. Thanks! :)

m13op22
  • 2,168
  • 2
  • 16
  • 35

2 Answers2

1

Wrap the entire code in a while True: block. Then, break when the user types No. Outside the loop print thanks, see ya:

while True:
    print('What tipe of information you want?')
    print('1. Basic Information (Title, Description, No Index and Canonical);\n2. 
      See the whole visible text;\n3. See top 10 words')
    print()
    resposta = input('Insert only number: ')
    if resposta == '2':
        print(output)

    if resposta == '3':
        print('Top 10 keywords are:')
        print(top)
    inp = input("Do you want any more information? Y or N")
    if inp == "N":
        break
print("thanks, see ya")
Anoop R Desai
  • 712
  • 5
  • 18
  • Thanks, man! It works like a charm. I just had to put some more "print()" on the code, or the questions would have no empty lines beetwen then. But it works. Thanks! – Vinicius Stanula Aug 28 '19 at 18:46
-1

Something like:

ask = True

while ask:
    char = input('Do you want information?')
    if char.lower() == 'y':
        #do stuff there
    else:
        ask = False
        break
Péter Leéh
  • 2,069
  • 2
  • 10
  • 23