Python Forum
tell me what's wrong with my code? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: tell me what's wrong with my code? (/thread-23486.html)



tell me what's wrong with my code? - codingisannoyingaf - Jan-02-2020

message1 = "Global Variable"

def myFunction():
    print("\nINSIDE THE FUNCTION")
    #Global variables are accessible
inside a function
    print(message1)
    #Declaring a local variable
    message2 = "Local Variable"
    print(message2)

#Calling the function
myFunction()

print("\nOUTSIDE THE FUNCTION")

#Global variables are accessible outside function
print (message1)

#Local variables are NOT accessible outisde function.
print (message2)
The program keeps saying "syntax error"

I copied it perfectly from the book, wtf?


RE: tell me what's wrong with my code? - Larz60+ - Jan-02-2020

Quote:The program keeps saying "syntax error"
Please post actual error, unaltered and complete (in error tags)


RE: tell me what's wrong with my code? - michael1789 - Jan-02-2020

(Jan-02-2020, 12:02 AM)codingisannoyingaf Wrote:
message1 = "Global Variable"

def myFunction():
    print("\nINSIDE THE FUNCTION")
    #Global variables are accessible
inside a function          <---------------- This should be commented out?
    print(message1)
    #Declaring a local variable
    message2 = "Local Variable"
    print(message2)

#Calling the function
myFunction()

print("\nOUTSIDE THE FUNCTION")

#Global variables are accessible outside function
print (message1)

#Local variables are NOT accessible outisde function.
print (message2)
The program keeps saying "syntax error"

I copied it perfectly from the book, wtf?



RE: tell me what's wrong with my code? - Larz60+ - Jan-02-2020

Not the code, the actual verbatim error message exactly as issued/


RE: tell me what's wrong with my code? - buran - Jan-02-2020

inside a function should be commented. probably in the book it's part of the comment on line 5


RE: tell me what's wrong with my code? - Axel_Erfurt - Jan-02-2020

#Global variables are accessible
inside a function          <---------------- This should be commented out?
yes it's the second line of the comment

'message2' is not defined

message1 = "Global Variable"
message2 = ""
 
def myFunction():
    print("\nINSIDE THE FUNCTION")
    #Global variables are accessible inside a function          <---------------- This should be commented out?
    print(message1)
    #Declaring a local variable
    message2 = "Local Variable"
    print(message2)
 
#Calling the function
myFunction()
 
print("\nOUTSIDE THE FUNCTION")
 
#Global variables are accessible outside function
print (message1)
 
#Local variables are NOT accessible outisde function.
print (message2)
Output:
INSIDE THE FUNCTION Global Variable Local Variable OUTSIDE THE FUNCTION Global Variable



RE: tell me what's wrong with my code? - adaomacarl - Jan-02-2020

Hi, thanks for sharing code.