A program is written to take in 20 numbers. It must then ensure that the numbers are between 0 and 100 (inclusive). The program then displays the average of these numbers. The program is written as below. Is this program fit-for-purpose or not and why?
total = 0
for i in range(20):
print("Please insert number", (i + 1))
n = int(input())
total = total + n
average = total / 20
A program is written to take in 20 numbers. It must then ensure that the numbers are between 0 and 100 (inclusive). The program then displays the average of these numbers. The program is written as below. Is this program fit-for-purpose or not and why?
total = 0
for i in range(20):
print("Please insert number", (i + 1))
n = int(input())
total = total + n
average = total / 20
number1 = int(input())
number2 = int(input())
number3 = int(input())
number4 = int(input())
number5 = int(input())
total = number1 + number2 + number3 + number4 + number5
print(total)
Using an array
Using a loop
Using predefined functions
This can be made more efficient by:
Using a conditional loop
Using a fixed loop
print(0)
print(2)
print(4)
print(6)
print(8)
print(10)
Using an array
Using a loop
Using predefined functions
This can be made more efficient by:
Using a conditional loop
Using a fixed loop
for i in range(0, 30):
print("Please insert a number")
if n > 50:
print("You gave me a number > 50")
break
Using an array
Using a loop
Using predefined functions
This can be made more efficient by:
Using a conditional loop
Using a fixed loop
try:
x = int(input())
print(x + 5)
except:
print("Cannot add the numbers together. Are you sure you provided an integer?")
#Program to calculate the average
#Written by J Balfour 2020
def john:
alice = 10
bob = 20
zelda = alice + bob
return zelda
if c > 10:
print("This line is indented")
Lookup the rules for identifiers in Python. For example, can they start with underscores?
Answer the questions on software evaluation
Try out the following past paper questions:
Apply a filter: