Looking for Informatics 1 - Introduction to Programming (2026-2027)[SEM1] test answers and solutions? Browse our comprehensive collection of verified answers for Informatics 1 - Introduction to Programming (2026-2027)[SEM1] at moodle1.maths.ed.ac.uk.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
After a successful call to the original function, a student adds:
print(total)
outside the function.
They argue: “The function has run, so total now exists and can be printed here.”
Explain why this reasoning is incorrect, and identify which variable outside the function holds the returned mean. [2 marks]
Suppose the call is changed to:
result = mean([])
Explain why the function cannot complete successfully as written. Describe a suitable way for the function to handle this case, and justify your choice. You do not need to write code. [2 marks]
Consider:
scores = {"Asha": 6, "Ben": 4, "Cara": 6, "Dan": 8}
passed = []
distinct_scores = set()
for name in scores:
if scores[name] >= 6:
passed.append(name)
distinct_scores.add(scores[name])
Explain what values name takes during the loop and what scores[name] retrieves. [2 marks]
After the loop finishes:
You may give the set’s values in any order. [3 marks]
The following code now runs:
saved = distinct_scores
saved.add(10)
print(10 in distinct_scores)
State the output and explain why it occurs. [2 marks]
Answer these two independent questions:
State the exact printed output and describe what the program calculates. [2 marks]
A student changes the loop to:
while current <= 7:
if current % 2 == 0:
continue
total = total + current
current = current + 1
The initial values are still current = 1 and total = 0.
Explain why this version never reaches the print statement. State the values of current and total once the program becomes stuck. [2 marks]
Return to the original program. Suppose only the increment is changed to:
current = current + 2
Would the final output change? Explain your answer by describing which values of current are processed. [2 marks]
Consider:
current = 1
total = 0
while current <= 7:
if current % 2 != 0:
total = total + current
current = current + 1
print("Total:", total)
Complete the table. Record total at the end of the iteration that processes the stated value of current. [2 marks]
Value of current being processed | total at the end of that iteration |
| 3 | |
| 4 | |
| 5 | |
| 7 |