Hey there! Sign in to join this conversationNew here? Join for free

python: SyntaxWarning:name "(variable name)" is assigned to before global decleration Watch

    • Thread Starter
    Online

    20
    ReputationRep:
    The code works and everything but every time i click to enter the details before it asks me the details this syntaxwarning comes down, how do i fix my code so it does not pop up?
    Attached Images
     
    • Thread Starter
    Online

    20
    ReputationRep:
    This is the syntax warning message
    Attached Images
     
    Offline

    2
    ReputationRep:
    You're doing "global" twice in your functions "country" and "money". You cannot do multiple global declarations in the same function.
    Make the variable global at the start of the function(s).

    If you have any problems, just PM me.

    For example -
    Code:
    x = 0
    def func(a, b, c): 
        if a == b:
            global x 
            x = 10 
        elif b == c: 
            global x 
            x = 20
    Code:
    Would be: 
    
    x = 0
    def func(a, b, c):
        global x #It's here
        if a == b:
            x = 10
        elif b == c:
            x = 20
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: January 24, 2017
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What newspaper do you read/prefer?
    Useful resources
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.