Computer Science - 4CP0 PearsonEdexcel

Subprograms

Gbogbo ọrọ náà

A long program that repeats the same block of code in five different places is fragile: fix a bug in one copy and the other four still carry it. Subprograms solve this by giving a named, reusable block of code a single home, one that any part of the program can call on whenever it is needed.

In this lesson you will learn the difference between procedures and functions, how to pass data into a subprogram using parameters and get data back out using a return value, and how local and global scope decide which parts of a program can see which variables. Every example is written in Python, one of the languages you can use for the Paper 2 practical programming exam.

Ebumnobi

  1. Understand the benefits of using subprograms and be able to write code that uses user-written and pre-existing (built-in, library) subprograms
  2. Understand the concept of passing data into and out of subprograms (procedures, functions)
  3. Be able to create subprograms that use parameters

Akọmọ Ojú-ẹkọ

A subprogram is a named, self-contained block of code that carries out a specific task and can be run, or 'called', from anywhere else in the program. Instead of writing the same lines of code repeatedly, a programmer writes them once inside a subprogram and calls that subprogram every time the task is needed.

Ọ dị na ngwa Green Bridge

Budata ngwa Green Bridge CBT na ekwentị maọbụ kọmputa gị iji nweta akwụkwọ ndụmọdụ zuru oke, ajụjụ mmụta, na ndị ọzọ.

Akwụkwọ ndụmọdụ zuru oke nwere eserese
Onye inyeaka mmụta AI
Mụọ n'ụzọ na-enweghị ịntaneti, oge ọbụla, ebe ọbụla
Ọ dị na Android, Windows, macOS, na Linux

Ayẹwo Ẹkọ

Ekele diri gi maka imecha ihe karịrị na Subprograms. Ugbu a na ị na-enyochakwa isi echiche na echiche ndị dị mkpa, ọ bụ oge iji nwalee ihe ị ma. Ngwa a na-enye ụdị ajụjụ ọmụmụ dị iche iche emebere iji kwado nghọta gị wee nyere gị aka ịmata otú ị ghọtara ihe ndị a kụziri.

Ị ga-ahụ ngwakọta nke ụdị ajụjụ dị iche iche, gụnyere ajụjụ chọrọ ịhọrọ otu n’ime ọtụtụ azịza, ajụjụ chọrọ mkpirisi azịza, na ajụjụ ede ede. A na-arụpụta ajụjụ ọ bụla nke ọma iji nwalee akụkụ dị iche iche nke ihe ọmụma gị na nkà nke ịtụgharị uche.

Jiri akụkụ a nke nyocha ka ohere iji kụziere ihe ị matara banyere isiokwu ahụ ma chọpụta ebe ọ bụla ị nwere ike ịchọ ọmụmụ ihe ọzọ. Ekwela ka nsogbu ọ bụla ị na-eche ihu mee ka ị daa mba; kama, lee ha anya dị ka ohere maka ịzụlite onwe gị na imeziwanye.

  1. Which keyword does a Python subprogram use to send a value back to the code that called it? A) global B) def C) return D) import Answer: C
  2. In def add(a, b): return a + b, what are a and b called? A) Arguments B) Parameters C) Return values D) Global variables Answer: B
  3. Which of these best describes a procedure? A) A subprogram that always returns a numeric value B) A subprogram that carries out a task but does not return a value C) A subprogram that can only be called once D) A built-in Python keyword Answer: B
  4. A variable is created inside a function using an assignment statement and is never declared global. What is its scope? A) It is global and can be read anywhere B) It is local to that function only C) It exists for the whole program but only after the function is called D) It has no scope in Python Answer: B
  5. Which statement must appear inside a subprogram before it can change the value of a variable defined outside every subprogram? A) local B) return C) global D) import Answer: C

Ọ dị na ngwa Green Bridge

Budata ngwa Green Bridge CBT na ekwentị maọbụ kọmputa gị iji nweta akwụkwọ ndụmọdụ zuru oke, ajụjụ mmụta, na ndị ọzọ.

Akwụkwọ ndụmọdụ zuru oke nwere eserese
Onye inyeaka mmụta AI
Mụọ n'ụzọ na-enweghị ịntaneti, oge ọbụla, ebe ọbụla
Ọ dị na Android, Windows, macOS, na Linux

Ọ dị na ngwa Green Bridge

Budata ngwa Green Bridge CBT na ekwentị maọbụ kọmputa gị iji nweta akwụkwọ ndụmọdụ zuru oke, ajụjụ mmụta, na ndị ọzọ.

Akwụkwọ ndụmọdụ zuru oke nwere eserese
Onye inyeaka mmụta AI
Mụọ n'ụzọ na-enweghị ịntaneti, oge ọbụla, ebe ọbụla
Ọ dị na Android, Windows, macOS, na Linux

Meecha Ajụjụ Ule Ọmarịcha

Ị chọrọ ime ajụjụ ule ọmarịcha gbasara Subprograms? Budata ngwa Green Bridge CBT iji nweta ajụjụ ule ọmarịcha na nyocha zuru ezu gbasara isiokwu a.

Dawunlodi Ẹpp naa lori Google Playstore.

Ihe nile ichoro iji nwee ihe ịga nke ọma na JAMB, WAEC & NECO.

Green Bridge CBT Mobile App
Personalized AI Ẹ̀kọ́ Ọ̀rọ̀ Alábàápàdé.
Egbò ọdúnrún IGCSE, JAMB, WAEC & NECO Ajùmọ̀ṣe ìbéèrè ti kọjá.
Ihe karịrị 1200 Nkọwa Nkuzi
Tallafi Ba Tare da Layin Intanet Ba - Koyi Duk Lokaci, Ko'ina
Jadawalin Gada Kore
Akọkọ akọle iwe & Ibeere agbara
Sọfụma Ọrụ Gi & Ọganihu Gi
Ìtọ́jú Ìtúmọ̀ fún Ẹ̀kọ́ Alábáyọrí.