Skip to content
MathsGenie logo
Open app

Course home

  1. GCSE
  2. Computer Science AQA
  3. Question bank

Programming concepts

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940
Question 25

A programmer has written the Python program below to calculate the sum of all integers from 1 to 4 inclusive.

total = 0
for number in range(1, 5):
    total = total + number
print(total)

The program needs to be modified so that it also calculates the product of (multiplies together) all of the integers from 1 to 4 inclusive.

Select the option that correctly modifies the program to achieve this.

total = 0
product = 1
for number in range(1, 5):
    total = total + number
    product = total * number
print(total)
print(product)
total = 0
product = 1
for number in range(1, 5):
    total = total + number
    product = product * number
print(total)
print(product)
total = 0
product = 1
for number in range(1, 5):
    total = total + number
    product = product * total
print(total)
print(product)
total = 0
product = 1
for number in range(1, 5):
    total = total + number
    product = (total + product) * number
print(total)
print(product)

Programming concepts Questions

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