0

Let us consider the following example:

import webbrowser
Cn=('Acharya Girish Chandra Bose College','AJC Bose College','Ananda Mohan College','Asutosh College','Bangabasi College','Barrackpore Rastraguru Surendranath College','Basanti Devi College')

Cnw={'Acharya Girish Chandra Bose College':'http://www.agcbosecollege.org/','AJC Bose College':'http://www.ajcbosecollege.org/','Ananda Mohan College':'http://anandamohancollege.ac.in/','Asutosh College':'http://www.asutoshcollege.in/','Bangabasi College':'http://bangabasi.org/home.php','Barrackpore Rastraguru Surendranath College':'http://www.brsnc.org/','Basanti Devi College':'http://www.basantidevicollege.edu.in/'}

yy=['Y','Yes','YES','y']
nn=['N','NO','no','No','n']
i=0
while i<=range(len(Cn)):
    print 'College Name : ',Cn[i]
    a=raw_input('Do u want to visit the website ? (Y/N) :')
    if a in yy:
        webbrowser.open(Cnw[Cn[i]])
    elif a in nn:
        break
    i=i+1

This program works fine, but I want to open next website after opening a webpage. This program open only one website and then opening another, but it skips one website every time. Here :
Image link here

After opening one website from list it will increase i by i=i+1 and again ask to me to open the next website. Please suggest to do this

1 Answer 1

1

I'm unsure as to why you're using range(), simply using len(Cn) is enough, however you should change it to i<len(Cn) so you don't go over the index on the last iteration of the while loop.

Additionally, when you break out in your elif statement, you end the loop. I'm unsure if this is what you're trying to do, if you would rather keep parsing through the list simply remove the elif statement. You also would not need your nn list of no variations.

import webbrowser
Cn=('Acharya Girish Chandra Bose College','AJC Bose College','Ananda Mohan College','Asutosh College','Bangabasi College','Barrackpore Rastraguru Surendranath College','Basanti Devi College')

Cnw={'Acharya Girish Chandra Bose College':'http://www.agcbosecollege.org/','AJC Bose College':'http://www.ajcbosecollege.org/','Ananda Mohan College':'http://anandamohancollege.ac.in/','Asutosh College':'http://www.asutoshcollege.in/','Bangabasi College':'http://bangabasi.org/home.php','Barrackpore Rastraguru Surendranath College':'http://www.brsnc.org/','Basanti Devi College':'http://www.basantidevicollege.edu.in/'}

yy=['Y','Yes','YES','y']
nn=['N','NO','no','No','n']
i=0
while i<len(Cn):
    print 'College Name : ',Cn[i]
    a=raw_input('Do u want to visit the website ? (Y/N) :')
    if a in yy:
        webbrowser.open(Cnw[Cn[i]])
    #elif a in nn:
    #   break
    i=i+1

Which gives me the following output:

College Name :  Acharya Girish Chandra Bose College
Do u want to visit the website ? (Y/N) :n
College Name :  AJC Bose College
Do u want to visit the website ? (Y/N) :n
College Name :  Ananda Mohan College
Do u want to visit the website ? (Y/N) :n
College Name :  Asutosh College
Do u want to visit the website ? (Y/N) :n
College Name :  Bangabasi College
Do u want to visit the website ? (Y/N) :n
College Name :  Barrackpore Rastraguru Surendranath College
Do u want to visit the website ? (Y/N) :n
College Name :  Basanti Devi College
Do u want to visit the website ? (Y/N) :n
>>> ================================ RESTART ================================
>>> 
College Name :  Acharya Girish Chandra Bose College
Do u want to visit the website ? (Y/N) :y
College Name :  AJC Bose College
Do u want to visit the website ? (Y/N) :y
College Name :  Ananda Mohan College
Do u want to visit the website ? (Y/N) :y
College Name :  Asutosh College
Do u want to visit the website ? (Y/N) :y
College Name :  Bangabasi College
Do u want to visit the website ? (Y/N) :y
College Name :  Barrackpore Rastraguru Surendranath College
Do u want to visit the website ? (Y/N) :y
College Name :  Basanti Devi College
Do u want to visit the website ? (Y/N) :y
>>> 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.