Question: Complete the given code to define three classes, Shape, Oval and Circle. The shape will be the parent class of Oval and Circle. Randomly create

Complete the given code to define three classes, Shape, Oval and Circle.

  • The shape will be the parent class of Oval and Circle.
  • Randomly create ten objects from Oval and Circle classes using theforloop given below
  • Your code should produce the correct number of Shapes, Circle and Oval objects. The count of objects should be calculated within the class definitions.
  • Example output (note that since it is random every time it will be a different number of shapes) \ There are 10 random shape objects ['Circle', 'Circle', 'Circle', 'Circle', 'Oval', 'Circle', 'Oval', 'Oval', 'Circle', 'Circle'] \ 3 of them are ovals \ 7 of them are circles \

This is the partial code to be completed

# Define Shape class

# Define Oval class

# Define Circle class

# Run the following lines of code

from random import choice

list_of_shapes = [choice(['Circle', 'Oval']) for x in range(10)]

for shape in list_of_shapes:

if shape == 'Oval':

#create object of oval

else:

#create object of circle class

# Print the list_of_shapes

# Print number of shape objects

# Print number of Oval objects

# Print number of circle objects

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!