Cambridge IGCSE and O Level Programming Book
INTERACTIVE SESSION >>> def my_function(): return 1,2
Task
>>> a,b = my_function() >>> print(a) 1 >>> print(b) 2 >>>
Task 3 Create a pseudocode and flowchart algorithm for an amended version of the circumference function. When passed the radius, this function returns the area and the circumference of a circle. Test that your algorithm works by programming and running the code in Python.
4.03 Programming a Procedure
28
The Python code for a procedure is similar to that used for a function. In this case empty brackets are used to show that no parameters are required by the subroutine. See how this works in the interactive session shown below: INTERACTIVE SESSION >>> def greeting(): print('Hello', 'Hello', 'Hello') >>> greeting() Hello Hello Hello >>>
Task
Notice how the greeting() function contains the built-in function, print().
Task 4 a Create a pseudocode algorithm for a procedure called dead_end()that prints out ‘I am sorry, you can go no further this way!’ This might then be called in a maze game whenever a player reaches the end of a passage. b Test that your algorithm works by programming the procedure in Python and providing a call to the procedure.
Programming a Procedure is outside the syllabus