Home » Python programs

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



Here, we are going to learn how to declare a list, input elements, append the elements in the list and finally, print the list?
Submitted by IncludeHelp, on July 26, 2018

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

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Quick links
Latest articles, Internship, Members
New...
Coding problems, Algorithms, Discrete Mathematics, Big data
Languages
C, C++, C++ STL, Java, Data Structure, C#.Net, Android, Kotlin, SQL
Web
PHP, Python, JavaScript, CSS, Ajax, Node.js, Web prog.
Programs
C, C++, DS, Java, C#, Python
Aptitude
C, C++, Java, DBMS
Interview
C, Embedded C, Java, SEO, HR
CS Subjects
CS Basics O.S. Networks DBMS Embedded Systems Cloud Computing Machine learning CS Organizations Linux DOS
More...
Articles, Puzzles, News/Updates


Recommended posts
C Tips & Tricks, C++ Tips & Tricks
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distros of 2018
C programming optimization techniques
Differences b/w C & Embedded C?
Embedded C Interview Q. & A.
C programming tips for Embedded Development
Basic rules of writing a C program
Important points (rules) to remember while writing C/C++ program
Top 5 Websites for solving programming challenges
Read more...


Others...
Computer G.K. (MCQ)
Most viewed pages...
Categories...



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.