Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
Question 43

An engineer is analyzing a discrete signal represented by a sequence of values xn=4n−1x_n = 4n - 1xn​=4n−1 for n=1n = 1n=1 to 5 inclusive. They have written a Python program to calculate the sum of these signal values:

signal_sum = 0
for n in range(1, 6):
    signal_sum = signal_sum + (4 * n - 1)
print(signal_sum)

To calculate the total energy of the signal, they need to modify the program so that it also calculates and outputs the sum of the squares of these individual signal values, i.e., ∑n=15(4n−1)2\sum_{n=1}^{5} (4n - 1)^2∑n=15​(4n−1)2.

Select the option that correctly implements this modification.

A
signal_sum = 0
energy = 0
for n in range(1, 6):
    signal_sum = signal_sum + (4 * n - 1)
    energy = energy + signal_sum ** 2
print(signal_sum)
print(energy)
B
signal_sum = 0
energy = 0
for n in range(1, 6):
    signal_sum = signal_sum + (4 * n - 1)
    energy = energy + (4 * n - 1) ** 2
print(signal_sum)
print(energy)
C
signal_sum = 0
energy = 0
for n in range(1, 6):
    signal_sum = signal_sum + (4 * n - 1)
    energy = energy + 4 * n ** 2 - 1
print(signal_sum)
print(energy)
D
signal_sum = 0
energy = 1
for n in range(1, 6):
    signal_sum = signal_sum + (4 * n - 1)
    energy = energy * (4 * n - 1) ** 2
print(signal_sum)
print(energy)
Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank