Subprograms: functions and procedures
Answers are for parents and teachers.
1
Write a function kub(x) that returns the cube of a number and print kub(3).
def kub(x): ⏎ return x ** 3 ⏎ print(kub(3))
2
Write a procedure that prints the numbers from 1 to n (1 2 3 4 for n = 4).
def sanash(n): ⏎ for i in range(1, n + 1): ⏎ print(i, end=" ") ⏎ sanash(4)
3
What is the recursive function fakt(3) equal to?
6
4
State the difference between a function and a procedure.
A function gives back a result with return; a procedure returns no value and only does something (for example, prints).