Question
The program below creates a list with 4 items. Each element value is an empty string (""). The user is asked for an input string, stored in newValue. Add 4 assignment statements between the list initialization and the final print() statement to assign the newValue to each element, using the numeric index for each element. When you are done, the final print() statement should display a list where all elements match the input value.
The following examples demonstrate the expected program output.
Enter new value: squirrel
['squirrel', 'squirrel', 'squirrel', 'squirrel']
Enter new value: LOL
['LOL', 'LOL', 'LOL', 'LOL']
values = ["","","",""]
newValue = input("Enter new value: ")
# add student code here
print(values)
The following examples demonstrate the expected program output.
Enter new value: squirrel
['squirrel', 'squirrel', 'squirrel', 'squirrel']
Enter new value: LOL
['LOL', 'LOL', 'LOL', 'LOL']
values = ["","","",""]
newValue = input("Enter new value: ")
# add student code here
print(values)
Answers
Answer
Traceback (most recent call last):
File "List.py", line 1, in <module>
values[0] = newValue
NameError: name 'newValue' is not defined
File "List.py", line 1, in <module>
values[0] = newValue
NameError: name 'newValue' is not defined
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.