Q:

Python | Program to input, append and print the list elements

belongs to collection: Python List Programs

0

Read the value of N (limit of the list), input N elements and print the elements in Python.

Example:

    Input:
    Enter limit of the list: 5
    Enter an integer: 10
    Enter an integer: 20
    Enter an integer: 30
    Enter an integer: 40
    Enter an integer: 50

    Output:
    Input list elements are:
    10
    20
    30
    40
    50

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# declare a list
list = []

# read limit (value of n)
# for maximum number of elements
n = int (input ("Enter limit of the list: "))

# input n integer element 
# and append to the list 
for i in range (n) :
	item = int (input ("Enter an integer: "))
	list.append (item)

# print all elements
print "Input list elements are: "
for i in range (n) :
	print list [i]

Output

    Enter limit of the list: 5
    Enter an integer: 10
    Enter an integer: 20
    Enter an integer: 30
    Enter an integer: 40
    Enter an integer: 50
    Input list elements are: 
    10
    20
    30
    40
    50

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python List Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Program to remove duplicate elements from... >>
<< Python | Program to find the position of minimum a...