Write a program to print the first half of values in one line and the last half of values in one line

Question:

With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half of values in one line and the last half of values in one line.

Hints:

  • Use [n1:n2] notation to get a slice from a tuple.

Solution:

tp=(1,2,3,4,5,6,7,8,9,10) tp1=tp[:5] tp2=tp[5:] print tp1 print tp2
Code language: Python (python)

Leave a Comment