Skip to content

Course home

Develop code

Develop code

EasyMediumHard
1234567891011121314151617181920212223242526
Question 10

An incorrect Python program is shown below.

The program should:

  • Generate a random integer between 1 and 20 (inclusive) representing the base of a triangle.
  • Set the height of the triangle to 10.
  • Calculate the area of the triangle using the formula: area=0.5×base×height\text{area} = 0.5 \times \text{base} \times \text{height}area=0.5×base×height.
  • Display the base, height, and area of the triangle with appropriate labels.

There are three errors in the code.

import random

base = random.randint(1, 20)
height == 10

area = 0.5 * base * height

print("Base is: " + base)
print("Height is: " + str(height))
print("Area is: " + str(Area))

Amend the code to correct the three errors.

[3]
Markscheme

Develop code Questions

  1. IGCSE
  2. /Computer Science
  3. /Develop code

62 exam-style questions on Edexcel IGCSE Computer Science Develop code. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank