RI Y2 CEP Lesson 4 Slides 2020
Uploaded by dontsueme · 10 December 2024
Preview
Lesson 4min max average storage . Remove letter . function in function . Calendar of Month problem . Reverse Cipher
Reminder: Who is Charles Babbage ?•Interesting facts or stories ?•What is his most significant work or contribution to this field ?•Contribute in forum
Example – min, max, average & storage•A group of students had a test (0 – 100) marks. •We want to know the following:•Lowest mark•Highest mark•Average mark•Keep the score of all students
Example – min, max, average & storage What if you want to stop the program by keying in an empty score. (another way to implement)
Example - Remove letter in string Write a function remove_letter(msg,letter) that takes a string msg and a single character letter. This function returns a string, which is msg with all occurrences of letter removed. This function is case sensitive, so ‘A’ is not the same as ‘a’. A sample run is shown below.>>> message = “a pack of pickled peppers”>>> remove_letter(message,’p’)“a ack of ickled eers”
Example - Remove letter in string What if I want to swap letter and not remove?
let’s think . . . and discuss . . .def f(g): return g(2)def square(x): return x**2def mystery(x): return x * (x + 1)>>>f(square)>>>f(mystery) What is going on ?
function in functionx = 5y = 10z = 15def f(x): def g(y): def h(z): return x + y + z return h(y) return g(x)print(f(6))What is printed ?
continue and break•The continue keyword causes Python to skip the remaining commands in the loop and go straight to deciding whether the loop should run again by testing the condition after the while keyword.•The break keyword, on the other hand, causes Python to immediately skip the remaining commands and exit the loop completely.
Content continues in the PDF.
Related notes
- SST (for revision practice) 2024 S3 Computing EOY P2 QP_FinalExam Papers · 2024
- Computing o level notes Notes/Practices · 2023
- BVSS Prelim P1 MSExam Papers · 2024
- BVSS Prelim P1 CPExam Papers · 2024
- CWSS Prelim P1 CPExam Papers · 2024
- CWSS Prelim P1 MSExam Papers · 2024

