Turn on thread page Beta

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

    • Thread Starter
    Offline

    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
    Offline

    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
Turn on thread page Beta
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.

This forum is supported by:
Updated: January 24, 2017
Poll
Do you think parents should charge rent?
Useful resources

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

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