110k views
0 votes
Initialize the list short_names with strings 'gus', 'bob', and 'zoe'. Sample output for the given program:

short_names = ['gus', 'bob', 'zoe']
for name in short_names:
print(name.capitalize())

User Jorne
by
6.9k points

1 Answer

5 votes

Final answer:

To initialize a list or tuple in Python, assign the values directly when declaring the variable. The list 'short_names' contains ['Gus', 'Bob', 'Zoe'], and the tuple 'team_names' contains ('Rockets', 'Raptors', 'Warriors', 'Celtics'). Use a for loop to print each element from the tuple.

Step-by-step explanation:

To initialize the list short names with the strings 'Gus', 'Bob', and 'Zoe', you can simply assign these values to the list when you declare it. Here is how you can write the code in Python:

short_names = ['Gus', 'Bob', 'Zoe']
print(short_names[0])
print(short_names[1])
print(short_names[2])
For the tuple team_names, you can initialize it with the strings 'Rockets', 'Raptors', 'Warriors', and 'Celtics', as follows:

team_names = ('Rockets', 'Raptors', 'Warriors', 'Celtics')
Then you can use a for loop to print each element in the tuple:

for team in team_names:
print(team)
This will display each of the team names on a separate line, corresponding to the sample output provided in the question.

completed question:

Initialize the list short names with strings 'Gus', 'Bob', and Zoe Sample output for the given program: Gus Bob Zoe 1 short_names - "Gus[0] 2 short names - 'Bob [1] 3 shortnames - "Zoe[2] 5 print (short names[0]) 6 print (short names[1]) 7 print (short names[23) =zyBooks ke My library > CSCI 151: Overview of Computer Science home 32 List basics Books catalog Help/FAQ Sato, Initiate the tuple team_names with the strings Rockets, Raptors, Warriors, and Celtics' (The top-4 2018 NBA teams at the end of the regular season in order) Sample output for the given program Rockets Raptors Warriors Celties Un ( • prince Sprinten princes lalia Named tuples

User PaulBarr
by
7.2k points