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

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

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

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

Algorithm:

Step1. Start

Step2. declare tp and assign values from 1 to 10.

Step3. Assign first 5 values of tp to tp1

Step4. Assign Last 5 values of tp to tp2

Step5.Print tp1.

Step6. Print tp2.

Step6.End

Program:

tp=(1,2,3,4,5,6,7,8,9,10)

tp1=tp[:5]

tp2=tp[5:]

print(tp1)

print(tp2)

Ouput:

>>>

(1, 2, 3, 4, 5)

(6, 7, 8, 9, 10)

>>> 

Python Comment | Creating a Comment | multiline comment | example

  1. Insert method , Remove Data From List , Remove Item From Position or from index , Remove method , Delete statement , Looping in list In Python
  2. list is data structure , oder collection , Append method , Extend method , Join List , Python
  3. Max and Min , Conversion of Tuple into list,string or list into tuple and it type , in Python
  4. Tuple without parenthesis , Tuple unpacking , list inside tuples Python
  5. While Loop and tuple in Python | find type of element and tuple with one element
  6. About Tuple in Python with examples | For loop and tuple | count , index len function slicing | Nested lists are obtained using nested indexing
  7. fromkeys method | copy method | clear method | get method in dictionary | python
  8. Python Dictionary | update() method
  9. Python Dictionary | Add data , POP , popitem , update method
  10. Generate a list and tuple with comma-separated numbers
  11. Define a function which generates Fibonacci series up to n numbers

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

Leave a Comment

Your email address will not be published. Required fields are marked *