Computer Science, asked by nsc95dsc51gaming, 4 months ago

1. Write a python script to combine first 2 and last 2 elements from the tuple.
eg :-
t= ("book", 2020, "CS", 500, "GRAM", "Thomas", "7 edition")
output must be :-
("book", 2020, "CS", "7 edition")​

Answers

Answered by allysia
21

Answer:

If you want the first and last 2 elements the output should be,

('book', 2020, '7 edition', 'Thomas')

And the program goes like:

\\\tt t= ("book", 2020, "CS", 500, "GRAM", "Thomas", "7 edition")\\\tt l=(t[0],t[1],t[-1],t[-2])\\\tt print(l)

If you want the wanted output as you mentioned,

The program goes like:

\\\tt t= ("book", 2020, "CS", 500, "GRAM", "Thomas", "7 edition")\\\tt l=(t[0],t[1],t[2],t[-1])\\\tt print(l)


BrainlyIAS: Nice :-)
Answered by jai696
18

\large\mathsf\color{pink}{Solution\: using\: python\: 3}

t = ("book", 2020, "CS", 500, "GRAM", "Thomas", "7 edition")

# combine first 2 and last 2 items

print(t[0:2] + t[-2:])

# output as shown in your question which is not what the question asks

print(t[0:3] + t[-1:])

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions