Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Develop code

EasyMediumHard
123456789101112131415161718192021222324252627
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]

Develop code Questions

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