Back to 课程

Computer Science GCES EDEXCEL

0% Complete
0/0 Steps
  1. Decomposition And Abstraction Edexcel
    2 主题
  2. Algorithms Edexcel
    11 主题
  3. Truth Tables Edexcel
    3 主题
  4. Binary Edexcel
    6 主题
  5. Data Representation Edexcel
    4 主题
  6. Data Storage And Compression Edexcel
    2 主题
  7. Hardware Edexcel
    5 主题
  8. Software Edexcel
    3 主题
  9. Programming Languages Edexcel
    2 主题
  10. Networks Edexcel
    7 主题
  11. Network Security Edexcel
    2 主题
  12. Environmental Issues Edexcel
    1 主题
  13. Ethical And Legal Issues Edexcel
    3 主题
  14. Cybersecurity Edexcel
    2 主题
  15. Develop Code Edexcel
    6 主题
  16. Constructs Edexcel
    4 主题
  17. Data Types And Data Structures Edexcel
    5 主题
  18. Operators Edexcel
    1 主题
  19. Subprograms Edexcel
    2 主题
课 Progress
0% Complete

Exam code:1CP2

Introduction to Using Subprograms

What is a subprogram? 

  • Subprograms are an out of line block of code that may be called by simply writing their name in a program

  • Subprograms are given a unique name so they can be called anywhere in a program

  • There are many benefits to using Subprograms, these include

    • Making bigger problems easier to break down (decompose) and code

    • Allows team members to be able to work on different parts of a problem

    • Makes the program easier to debug

    • Makes programs more efficient as code is not duplicated

  • There are two main types of subprogram:

    • Procedures – does not return a result

    • Functions – returns one or more results to the calling code

Examples of using subprograms

Python code

# Subprogram 1 - Procedure

def Information() #define a subprogram named 'information'

first_name = input("Enter a name")

surname = input("Enter a name")

# Subprogram 2 - Function

def Tax(pay_per_hour, hours_worked) #define a subprogram that takes 2 parameters

total = pay_per_hour * hours_worked

net_pay = total * 0.8

return net_pay

#Main program starts here

Information() #call subprogram 1
print(Tax) #call subprogram 2

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注