Oct-31-2019, 03:39 AM
(This post was last modified: Oct-31-2019, 03:39 AM by newbieAuggie2019.)
(Oct-30-2019, 11:03 PM)sik Wrote: Can someone please explain to me why this doesn't work?Hi!
answer=(input(""" 1 To open BBC 2 To open Wikipedia 3 To open NASA """) if answer==1: webbrowser.open(web1) elif answer==2: webbrowser.open(web2) elif answer==3: webbrowser.open(web3)
Input() gets what you type as strings, so I would then transform the values into strings ('1', '2', '3', instead of 1, 2, 3):
if answer=='1': webbrowser.open(web1) elif answer=='2': webbrowser.open(web2) elif answer=='3': webbrowser.open(web3)Also, you have missed the last parenthesis in answer (with the multiline input() function), and finally, you have to call the function that you have created on the last line (webpage()):
def webpage(): import webbrowser web1="http://www.bbc.co.uk/" web2="http://en.wikipedia.org/wiki/Main_Page" web3="http://www.nasa.gov/" answer=(input(""" 1 To open BBC 2 To open Wikipedia 3 To open NASA """)) if answer == '1': webbrowser.open(web1) elif answer == '2': webbrowser.open(web2) elif answer == '3': webbrowser.open(web3) webpage()I checked and now it works.
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs