हिंदी

Write a program to input n numbers and to insert any number in a particular position.

Advertisements
Advertisements

प्रश्न

Write a program to input n numbers and to insert any number in a particular position.

कोड लेखन
Advertisements

उत्तर

Store n numbers in a list and use insert(position, number) to insert a number at the specified position.

n = int(input("Enter number of elements: "))
numbers = []

for i in range(n):
    number = int(input("Enter a number: "))
    numbers.append(number)

position = int(input("Enter position: "))
number = int(input("Enter number to insert: "))
numbers.insert(position, number)

print("List after insertion:", numbers)
 
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1: Review of Phython - EXERCISE [पृष्ठ २७]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 1 Review of Phython
EXERCISE | Q 27. | पृष्ठ २७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×