78.9k views
3 votes
Write a program that uses an initializer list to store the following set of numbers in a list named nums. Then, print the first and last element of the list.

56 25 -28 -5 11 -6

Sample Run
56
-6

User Awesomo
by
7.0k points

1 Answer

4 votes

List and Print Elements.

Here's a possible implementation of the program in Python:

python

Copy code

nums = [56, 25, -28, -5, 11, -6]

print("First element:", nums[0])

print("Last element:", nums[-1])

The output of the program would be:

sql

Copy code

First element: 56

Last element: -6

In this program, we first define a list named nums using an initializer list with the given set of numbers. Then, we use indexing to access the first and last elements of the list and print them to the console. Note that in Python, negative indices can be used to access elements from the end of the list, so nums[-1] refers to the last element of the list.

ChatGPT

User Amzath
by
8.4k points