Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Python function problem

    Can someone please explain to me why this is not working.

    def x():
    u = input("Please enter your name: ")
    x()
    Please enter your name: Kieran
    print(u)

    Name Error: Name 'u' is not defined.

    How do i go about defining a variable whilst creating a function?
    ps I am new to python and coding in general as im sure you can tell.

  • #2
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh I see now, the variable is local. Is there anyway I can use these variables outside of the function itself?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •