Using sub programs
There are different types of sub programs. Built-in sub programs such as print() and len() and user-defined sub programs.
User-defined sub program can be either PROCEDURES (chunks of code that perform a task when called) and FUNCTIONS (chunks of code that perform a task when called AND return a value back to the main program.
Section 7 of the CSNEWBS website goes over the basics and includes examples and challenges.
User-defined sub program can be either PROCEDURES (chunks of code that perform a task when called) and FUNCTIONS (chunks of code that perform a task when called AND return a value back to the main program.
Section 7 of the CSNEWBS website goes over the basics and includes examples and challenges.
Now watch the video......
Now take the test
Programming task
Below are some lines of code for a program that removes duplicate (repeated) values from a list and then prints out the list, without the duplicates.
A sub-program is used to find and remove the duplicates.
The lines of code are slightly jumbled up.
Your task is to re-order the code so that the program works AND to add comments to EVERY line explaining the purpose of the line. Copy and paste the code below into a Thonny or Repl.it file, then share or upload it to me.
A sub-program is used to find and remove the duplicates.
The lines of code are slightly jumbled up.
Your task is to re-order the code so that the program works AND to add comments to EVERY line explaining the purpose of the line. Copy and paste the code below into a Thonny or Repl.it file, then share or upload it to me.
The code
nums = [3,5,6,5,7,3,8,9,2,3,6] #
def remove_duplicates(numsIn): # nums2 = [] # if item not in nums2: # for item in numsIn: # nums2.append(item) # no_duplicates = (remove_duplicates(nums)) # print(no_duplicates) # return nums2 # |
|