A computer program calculates the total salary of its employees.
It calls a procedure to do the tax calculation and update the salary.
A negative number entry will stop the program loop.
Here is the entire program written in pseudocode:
DECLARE salary, totalSalary:INTEGER
initialise a global variable totalSalary to 0.
totalSalary ← 0
INPUT salary
WHILE salary > 0 DO
updateSalary(salary)
INPUT salary
END WHILE
OUTPUT "The total salary is ", totalSalary
The procedure updateSalary:
Code/Implement the procedure and test your solution with the above program.
Translate the following program code to pseudocode
#COMPUTER PROGRAM
#ages is an array of REAL - GLOBAL VARIABLE
ages = []
#i, rand are an INTEGERs
i = 9
while i >= 0:
rand = random.randint(1,100)
processRand(rand)
i = i-1
#PROCEDURE DEFINITION
def processRand(number):
global ages
if num%2 == 0:
ages.append(num)
else:
ages.append(-1)
Adapt your original code so that it no longer uses global variables.
Save your file as scope-2.py
Can you write a program which includes a global variable(s) and functions and/or procedures in Python?
If you cannot think of an idea, adapt a task that you complete in the FUNCTIONS or PROCEDURES unit.