- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Function Invoking
def sumN(n):
sum = 0
for i in range(n+1):
sum = sum + i
print(sum)
def sumNCube(n):
sum = 0
for i in range(n+1):
sum = sum + i**3
print(sum)
def main():
print( sumN(5), sumNCube(5) )
main()
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Pass by value
def main():
aList = [1, 2, 3]
print(aList)
append(aList, 4)
print(aList)
def append(s, n):
s = s + [n]
print("This updated list is", s)
main()
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Modifying a list in a function
def main():
aList = [1, 2, 3]
print(aList)
double(aList)
print(aList)
def double(s):
for i in range(len(s)):
s[i] = s[i] * 2
print("This updated list is", s)
main()