GalaxyWolf75
GalaxyWolf75

Reputation: 11

Can't break out of a loop when I am using the right thing

def G(): 
    def gl(): 
        url = ("www.google.com");
        webbrowser.open_new(url);   ##takes me to google
        exit();

    def glin(): 
        os.startfile("C:\Program Files\M Google\Google Chrome.lnk");    ##takes me to google incognito
        exit();

    while 1: 
        what_to_doG = input("choosing which one of glin or gl");  ##chooses which one of the above to go to
        if ( what_to_doG == gl): 
            gl();
            break;


        if ( what_to_doG == glin): 
            glin();
            break;


while 1: 
    what_to_do = input("choosing out of G or B");

    if ( what_to_do == G): 
        G();                           ##chooses which one to go to
        break;
  ##   ^^^^^^--- this won't take me to G() and won't break out

    if (  what_to_do == B): 
        B();
        break;

when i run this it keeps going back to the "choosing out of G or B" even tho i am putting G please help me someone and i am making this to get to tabs faster

Upvotes: 0

Views: 36

Answers (2)

JahKnows
JahKnows

Reputation: 2706

Try this. You need to compare your strings to strings as in what_to_do == 'G'

def G(): 
    def gl(): 
        url = ("www.google.com")
        webbrowser.open_new(url)
        exit()

    def glin(): 
        os.startfile("C:\Program Files\M Google\Google Chrome.lnk")   
        exit()

    while 1: 
        what_to_doG = input("choosing which one of glin or gl");  
        if what_to_doG == 'gl': gl()
        elif what_to_doG == 'glin': glin()
        break


while 1: 
    what_to_do = input("choosing out of G or B")
    if what_to_do == 'G': G()
    elif what_to_do == 'B': B()
    break

Upvotes: 1

Brandaboss
Brandaboss

Reputation: 47

What I noticed when I ran your code is that you need to put quotes around G and B like this:

if ( what_to_do == 'G'): 
    G();                           ##chooses which one to go to
    break;

if (  what_to_do == 'B'): 
    B();
    break;

It worked for me after that. Hope this helps! Edit: you also need to put quotes around glin and gl

Upvotes: 0

Related Questions