list input in python

Description

Python Program to get list size n and n elements of list, then print the elements.
Input:
5
5 7 9 3 1
Output:
5 7 9 3 1

Solution

l=list(map(int,input("Enter array elements:").split(" ")))
for i in l:
    print(i)

Explanation

To get list of numbers seprated by space, use split(" ") method. Split() method splits the numbers as seprate elements. 
By default this methods are considered as string, since input() method returs string.

Use map() function to convert all elements as integer and store it in list.



Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution