134k views
2 votes
In the program below, which two variables have the same scope?

def welcome(strName):
greeting = "Hello " + strName
length = len(strName)
print (greeting, length)

def average(numA, numB):
sumNumbers = numA + numB
ave = sumNumbers / 2
return ave

myName = 'Jaynique'
myAverage = average(3, 7)
welcome (myName)
print (myAverage)

sumNumbers and ( choices are 3+7 , ave , strName)

2 Answers

6 votes

Final answer:

The two variables with the same scope in the provided program are 'sumNumbers' and 'ave', as they are both local to the 'average' function.

Step-by-step explanation:

In the provided program, the two variables that have the same scope are sumNumbers and ave. They are both defined within the average function and are not accessible outside of it. They are local to the average function, meaning they can only be used within the function itself. On the other hand, strName is a parameter of the welcome function and has scope only within that function.

User Hallski
by
8.4k points
2 votes

Answer:

sumNumbers and ave have the same scope within the average() function, but are not related to the welcome() function or the myName variable. strName has its own scope within the welcome() function. 3+7 is not a variable, but rather a value that is passed as arguments to the average() function.

User Steven Elliott
by
9.0k points