Question 12 (5 marks) The for loop below uses the modulo operator to calculate the sum of all integers between 1 and 23 which are evenly divisible by 3. Write a function called mod_sum that encapsulates the code below. (1) Your function does not need any argument as input but should has a 'return' statement; (2) Your function should include a Docstring and appropriate comments. result = 0 for num in range(1, 24): if (num % 3 == 0): result = result + num

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question
Question 12 (5 marks)
The for loop below uses the modulo operator to calculate the sum of all integers between 1
and 23 which are evenly divisible by 3. Write a function called mod_sum that encapsulates the
code below. (1) Your function does not need any argument as input but should has a 'return'
statement; (2) Your function should include a Docstring and appropriate comments.
result = 0
for num in range(1, 24):
if (num % 3 == 0):
result = result + num
Transcribed Image Text:Question 12 (5 marks) The for loop below uses the modulo operator to calculate the sum of all integers between 1 and 23 which are evenly divisible by 3. Write a function called mod_sum that encapsulates the code below. (1) Your function does not need any argument as input but should has a 'return' statement; (2) Your function should include a Docstring and appropriate comments. result = 0 for num in range(1, 24): if (num % 3 == 0): result = result + num
Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Load Event
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning