Getting startedFunctionsVariablesVariables 2InputsSelectionFlowchartsData typesPseudocode1Pseudocode2Subprogram1Subprogram2 |
SubprogramsA subprogram is a piece of code that can be used over and over again. If you were coding a calculator, you could make a subprogram that only does adding. Every time you need to do adding, you can use the same subprogram.
Here is a simple subprogram: number1=int(input("Enter a number: ")) number2=int(input("Enter another number: ")) def adding(num1, num2): total=num1 + num2 print(total) adding(num1, num2): This subprogram explained:
Test you knowledge
Loading Sub programs2
A program with 5 subprogramsLook at the code below
It has 5 subprograms. 4 of them do stuff, while the last one executes all the others. Look at line 21 because this is where the code begins. |