Exercise 4

Exercise 4
1 / 4
volgende
Slide 1: Tekstslide
Ilearningdeal@gmail.comFurther Education (Key Stage 5)

In deze les zitten 4 slides, met tekstslides.

time-iconLesduur is: 100 min

Onderdelen in deze les

Exercise 4

Slide 1 - Tekstslide

Make an Array that stores 5 subject names – Maths, English, Computing, Art and Science
Use the built in function (print) that prints each subject name out from the array.
Create your own function to tell you how many objects the array contains and call this function successfully in the program 
Insert your code for this project using copy and paste from your programming environment. Annotate this code below using in-line programming comments

a) where you use an array to store data
b) where you call a function to return a value and
c) where you use a built-in function to return a value  


Slide 2 - Tekstslide

 1. Create the array (list) with 5 subject names
subjects = ["maths", "english", "computing", "art", "science"]
# 2. Define a custom function to count items in the array
def get_array_length(target_array):
    count = len(target_array)
    return count



# 3. Use the built-in print function to output each subject
# We use a 'for' loop to iterate through the array
for item in subjects:
    print(item)
# 4. Call the custom function and print the result
total_subjects = get_array_length(subjects)
print("\nThe array contains", total_subjects, "objects.")

Slide 3 - Tekstslide

END

Slide 4 - Tekstslide