I'm new to python and was playing with worked examples textbook from http://do1.dr-chuck.com/pythonlearn/EN_us/pythonlearn.pdf section.4.9 user defined functions. I got confused along the way.
(I was pointed to post Short description of the scoping rules? but all its answers but found it too advanced for my beginner-level question )
when code round0 was:
bruce=input("please enter what to be printed 2x")
def printTwice(bruce):
print(bruce)
print(bruce)
printTwice("alpha")
regardless of what input i gave, it came out as "alpha". OK , i get it, "alpha" is set as value for "bruce" here.
round1:
bruce=input("please enter what to be printed 2x") #to input "hello"
not1=123
def printTwice(not1): #set parameter to not1 , not1 is set as 123 , but output is what was given in input
print(bruce)
print(bruce)
printTwice("a")
output turns out to be whatever is inputted for bruce. e.g. "hello"
Q: Why does it ignore arguments "a" and "not1" and take input "hello" for bruce ?
Round 2: #Since i saw python wasn't paying attention to what i ask it to do, i removed quotes for "a" , to be a
bruce=input("please enter what to be printed 2x")
not1=123
def printTwice(not1): #set parameter to not1 , not1 is set as 123 , but output is what was given in input
print(bruce)
print(bruce)
printTwice(a) # argument doesn't have " " now
outcome : NameError: name 'a' is not defined. Q: why does it now bother what i placed into the parenthesis this time but not round 0 nor round 1?
I understand my question is beginner or maybe duplicated somewhere, if so, please point me to the right post. Thank you!