Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 tell me what's wrong with my code?
#1
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?
Larz60+ wrote Jan-02-2020, 12:58 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
Quote:The program keeps saying "syntax error"
Please post actual error, unaltered and complete (in error tags)
Quote
#3
(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?
Quote
#4
Not the code, the actual verbatim error message exactly as issued/
Quote
#5
inside a function should be commented. probably in the book it's part of the comment on line 5
Quote
#6
#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
Quote
#7
Hi, thanks for sharing code.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Manipulating index value, what is wrong with this code? Emun 1 126 Feb-05-2020, 07:18 AM
Last Post: perfringo
  What is wrong with my chemistry code? mimimycin 9 306 Dec-30-2019, 06:43 PM
Last Post: mimimycin
  I don't know what's wrong with this code [Python Console] H0M1C1D4L_P1G 6 247 Dec-22-2019, 10:27 PM
Last Post: snippsat
  what's wrong with my code Oaklizard2047 4 188 Nov-03-2019, 06:16 AM
Last Post: Oaklizard2047
  python gives wrong string length and wrong character thienson30 2 281 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  How does the code run? My code wrong? jollydragon 0 200 Oct-10-2019, 06:24 AM
Last Post: jollydragon
  What's wrong with this code? kumaaaa 6 373 Sep-28-2019, 12:06 PM
Last Post: DeaD_EyE
  Wrong output in Visual Studio Code py_learner 1 336 Jun-24-2019, 10:02 PM
Last Post: Yoriz
  elevator simulator...whats the wrong at this code? tasos710 5 1,375 Jun-11-2019, 01:38 AM
Last Post: micseydel
  can't figure out what is wrong with this code morganbyng9 2 695 Oct-09-2018, 06:50 PM
Last Post: stullis

Forum Jump:


Users browsing this thread: 1 Guest(s)