Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

question: 7 which of the following programs would alter my_list to cons…

Question

question: 7
which of the following programs would alter my_list to consist of the following:
red, green, blue, orange, yellow

my_list = red, green, blue, orange
my_list.append(yellow)

my_list = red, green, blue, orange
my_list.extend(yellow)

my_list = red, green, blue, orange
my_list.replace(yellow)

my_list = red, green, blue, orange
my_list.add(yellow)

Explanation:

Step1: Analyze initial list

Initial my_list = ['red', 'green', 'blue', 'orange'] (4 elements). Target list adds 'yellow' at end (5 elements).

Step2: Check first option

append('yellow') adds element to list end. Result: ['red', 'green', 'blue', 'orange', 'yellow'] (matches target).

Step3: Verify other options

  • extend('yellow') splits string into chars: adds ['y','e','l','l','o','w'] → wrong.
  • replace('yellow') is not a Python list method → invalid.
  • add('yellow') is not a Python list method → invalid.

Answer:

The first option (my_list = ['red', 'green', 'blue', 'orange']; my_list.append('yellow'))