Sub-process: Difference between revisions
Mr. MacKenty (talk | contribs) No edit summary |
Mr. MacKenty (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[file:arrows.png|right|frame|Explaining sub-processes<ref>http://www.flaticon.com/</ref>]] | [[file:arrows.png|right|frame|Explaining sub-processes<ref>http://www.flaticon.com/</ref>]] | ||
The role of a sub process is | The role of a sub-process is to make a problem easier to solve, especially when a problem requires repetition. A sub-process is synonymous with a [[functions|function]]. | ||
== | == What is a sub-process == | ||
A sub-process is a '''named-part''' of a larger process. This sub-process can be called many times, like a function. A sub-process accepts input, processes the input, and returns a result. | |||
=== Example === | === Example === | ||
Imagine we had a program which described monsters. The description of a monster can be ONLY ONE OF the following: | |||
# fluffy | |||
# spikey | |||
# slimy | |||
# scary | |||
If we had 10 different monsters would it make sense for us to write this conditional 10 times? | |||
<syntaxhighlight lang="python"> | |||
def description_of_monster(value): | |||
if value == 1: | |||
return "fluffy" | |||
elif value == 2: | |||
return "spikey" | |||
elif value == 3: | |||
return "slimy" | |||
else: | |||
return "scary" | |||
</syntaxhighlight> | |||
... of course not! It makes much more sense to create a sub-process so we can avoid repetition, increase efficiency, make our code more understandable. | |||
== Standards == | == Standards == |
Latest revision as of 06:41, 19 November 2020
The role of a sub-process is to make a problem easier to solve, especially when a problem requires repetition. A sub-process is synonymous with a function.
What is a sub-process[edit]
A sub-process is a named-part of a larger process. This sub-process can be called many times, like a function. A sub-process accepts input, processes the input, and returns a result.
Example[edit]
Imagine we had a program which described monsters. The description of a monster can be ONLY ONE OF the following:
- fluffy
- spikey
- slimy
- scary
If we had 10 different monsters would it make sense for us to write this conditional 10 times?
def description_of_monster(value):
if value == 1:
return "fluffy"
elif value == 2:
return "spikey"
elif value == 3:
return "slimy"
else:
return "scary"
... of course not! It makes much more sense to create a sub-process so we can avoid repetition, increase efficiency, make our code more understandable.
Standards[edit]
These standards are used from the IB Computer Science Subject Guide[2]
- Explain the role of sub-procedures in solving a problem.
References[edit]
- ↑ http://www.flaticon.com/
- ↑ IB Diploma Programme Computer science guide (first examinations 2014). Cardiff, Wales, United Kingdom: International Baccalaureate Organization. January 2012.