Skip to content Skip to sidebar Skip to footer

What Is Wrong With This Input Code?? And Browser Launcher In Python

this is the code ...................................................when it runs it will only run the redditNeed == 1 and it opens 5 windows. And then when i hit any other the o

Solution 1:

A couple of things:

  1. You should use raw_input;
  2. You should only import webbrowser once, at the top of the script;
  3. Rather than branching elifs, use a dictionary to hold the options; and
  4. You can use webbrowser.open'snew argument to try to open a new tab.

Putting that together:

import webbrowser

reddits = {1: {"name": "Front Page", "url": "http://reddit.com"}, ...}

print("Which Reddit do you want?")
for r insorted(reddits):
    print("{0}. {1[name]}".format(r, reddits[r])
reddit_need = int(raw_input("Enter a number: "))

webbrowser.open(reddits[reddit_need]["url"], 2)

Solution 2:

Your indentation is incorrect. Move the if statements back to the same indent as redditNeed == stuff

Post a Comment for "What Is Wrong With This Input Code?? And Browser Launcher In Python"