Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    20
    ReputationRep:
    Our teacher is telling us to use it for the coursework but i dotn understand what the function of global ( name) is?
    Online

    16
    ReputationRep:
    Really? My teacher said that using global variable makes you loose marks.

    A global variable is essentially a variable that is accessible throughout the program (not just in one variable).
    Offline

    17
    ReputationRep:
    Generally most people say not to use global variables but depending on the task, they may be more efficient.

    Local variable is something that only is accessible in one function. While global can be used through out. So

    a = "hello"
    Def example():
    b = "world"
    Print(a)
    Print(b)

    Def example2():
    Print(a)
    Print(b)

    Run example() and result will be "hello" "world"
    Run example2() and you'll get "hello" and then an error for non existent variable because it's only available in example()
 
 
 
  • 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
    Have you ever participated in a Secret Santa?
    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.