Function Parameter Variables in Python
Let us have the following function:
pythondef func(num):
return num ** 2
Let's call the function, passing the number 2 as a parameter:
pythonprint(func(2))
However, it is not necessary to pass a number - you can also use a variable containing the value we need:
pythontst = 3
print(func(tst)) # 9
Задание 1
Three variables with numbers are given:
pythontst1 = 2
tst2 = 4
tst3 = 6
Make a function that will take three numbers as parameters and find their sum. Display the sum of the variables specified above.
Задание 2
Given a function func and a variable tst:
pythondef func(lst):
sum = 0
for el in lst:
sum += el
return sum
tst = [1, 3, 6]
Use the function to find the sum of the elements of the variable tst.