-2
import webbrowser

T = "www.twitter.com"
R = "www.reddit.com"
Y = "www.youtube.com"
while True:
    print('Enter T for Twitter')

    print('Enter R for Reddit')

    print('Enter Y for Youtube')

    input()
    if (T):
        webbrowser.open_new("www.twitter.com")
        break
    elif (R):
        webbrowser.open_new("www.reddit.com")
        break
    elif (Y):
        webbrowser.open_new("www.youtube.com")
        break
    else:
        print('Invalid selection, try again.')
        continue

What am I missing? I'm sorry if the answer is obvious, i'm new to Python3 and have been trying for hours..

  • 3
    `if (T):` is ***ALWAYS*** `True`. You do not store the result of `input` into a variable and you do not compare that non-existant variable to `T`, `R` or `Y`. – luk2302 Oct 26 '22 at 10:45
  • 1
    Your `input()` pauses to take input from the user, but you throw away the result and just test the first of your three strings (all of which are truthy) and open a new window with twitter and stop the program. – quamrana Oct 26 '22 at 10:46
  • 2
    Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – luk2302 Oct 26 '22 at 10:47

1 Answers1

0
import webbrowser

T = "www.twitter.com"
R = "www.reddit.com"
Y = "www.youtube.com"
print('Enter T for Twitter')
print('Enter R for Reddit')
print('Enter Y for Youtube')
a=input()
while True:
    if a in "Tt":
        webbrowser.open_new("www.twitter.com")
        break
    elif a in "Rr":
        webbrowser.open_new("www.reddit.com")
        break
    elif a in "Yy":
        webbrowser.open_new("www.youtube.com")
        break
    else:
        print('Invalid selection, try again.')

Try this code.