I want my program to ask a value of n. After user inputs the value,
program takes input for n values and stores them in a list or something like array (in C).
Input must be in the format:
Enter value of n: 4
2
5
7
1
I want to store this input in a list for my later use.
The simplest approach is something like this:
However this has a number of problems:
Instead you can use raw_input and parse the result as an integer. You will also need error handling in the appropriate locations. How you handle errors depend on the program.
You might find this function might be useful as a starting point:
Note that the behaviour of input and raw_input has changed between Python 2.x and Python 3.x. Python 3.x’s input function behaves like Python 2.x’s raw_input function.