Take multiple inputs from user

taking multiple inputs in python 3
how to take multiple inputs in python using for loop
how to take n inputs in python
"python 3" input multiple lines
how to take multiple inputs in one line in c
split multiple inputs into separate lines
how to take unknown number of inputs in python
how to take multiple input in dictionary in python

I want to get user input from user. I have created a function to do that by taking the code from node.js documentation. But I cannot receive multiple user inputs. How can I do that? This is the code so far.

function getUserInput() {
        rl.question('Please input a letter: ', (answer) => {
        console.log('Letter entered: ${answer}');
        rl.close();
        }); 
    }

//getUserInput();

var k=0; 
while ( k < 3 ){
        getUserInput();
        k++;
    } 

I expect to take for example 3 user inputs. I want to take user input. With the code above I can only take only ONE user Input. I thought adding the function into a loop so it could work. I am looking for any modification into my code so It can work and so I can take more than one user input.

I think the problem is that rl.question waits for an input before proceeding but the while loop doesn't. Here's a simple node cli that does what you're after, I think. Just save this code in a file named index.js and go to the directory and type: node index.js

 // Dependencies
 var readline = require('readline');

 var cli = {};

 // Init function
 cli.init = function(){
   // Send the start message to the console in magenta
   console.log('\x1b[35m%s\x1b[0m',"The CLI is running");

   // Start the interface
   var _interface = readline.createInterface({
     input: process.stdin,
     output : process.stdout,
     prompt : '>'
   });

   var arrayOfInputs = [];
   var k = 0;
   var max = 3;
   cli.getUserInput = function(){
     _interface.question("Ask Something? ", function(str){
       k++;
      arrayOfInputs.push(str);
      if(k < max){
        cli.getUserInput();
      } else {
        console.log(...arrayOfInputs);
      }
    });
   };

   cli.getUserInput();

 };

 cli.init();

How to input multiple values from user in one line in Python , Reads two numbers from input and typecasts them to int using. # list comprehension. x, y = [ int (x) for x in raw_input ().split()]  I expect to take for example 3 user inputs. I want to take user input. With the code above I can only take only ONE user Input. I thought adding the function into a loop so it could work. I am looking for any modification into my code so It can work and so I can take more than one user input.

Taking multiple inputs from user in python, This might prove useful: a,b=map(int,raw_input().split()). You can then use 'a' and 'b' separately. Taking multiple inputs from user in Python Developer often wants a user to enter multiple values or inputs in one line. In C++/C user can take multiple inputs in one line using scanf but in Python user can take multiple values or inputs in one line by two methods. Using split () method

This appears to be using something like the promises API.

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
}); 


function getUserInput(n) {
    rl.question('Please input a letter: ', (answer) => {
        console.log(`Letter entered: ${answer}`);
        if (n < 3) {
            getUserInput(n+1);
        } else {
            rl.close();
        }
    }); 
}

getUserInput(1);

When I run it, this happens:

$ node getinput.js
Please input a letter: a
Letter entered: a
Please input a letter: b
Letter entered: b
Please input a letter: c
Letter entered: c

Python Input, At times, we might want to take multiple inputs from the user and in this case, we can use the raw_input ( ) or input ( ) function multiple times. The task is to take multiple inputs from the user, for this we can use split() method. split() method. split() method is a library method in Python, it accepts multiple inputs and brakes the given input based on the provided separator if we don’t provide any separator any whitespace is considered as the separator. Syntax:

How to input multiple values from user in one line in Python?, To read multiple variables in language C, we write something like −//Read three variable in one line scanf(“%d %d %d”, &x, &y, &z)Currently  In Python, to provide multiple values from user, we can use − input () method: where the user can enter multiple values in one line, like − >>> x, y, z = input(), input(), input() 40 30 10 >>> x '40' >>> y '30' >>> z '10' From above output, you can see, we are able to give values to three variables in one line.

Taking multiple inputs from user in Python, Developer often wants a user to enter multiple values or inputs in one line. In C++​/C user can take multiple inputs in one line using scanf but in Python user c. Deleting a User in Linux using Python Script; Python Tweepy – Getting the time when a user was created; User-defined Exceptions in Python with Examples; Taking multiple inputs from user in Python; Python | Fetch your gmail emails from a particular user; Python Tweepy – Getting the number of tweets a user has tweeted

python how to take multiple inputs from user in function, how to take multiple inputs from user in function. How i can take Multiple i.e may be user enter 2 input or 3 input etc from user using variable  One solution is to use raw_input () two times. Note that we don’t have to explicitly specify split (‘ ‘) because split () uses any whitespace characters as delimiter as default. One thing to note in above Python code is, both x and y would be of string. We can convert them to int using another line.

Comments
  • Hey! Welcome to StackOverflow! Please check this one: codereview.stackexchange.com/questions/134048/…
  • There isn't enough information provided to get a clear understanding of what you're trying to achieve. Could you provide more information?
  • Let me write it here and I will add to the description. I want to take user input. With the code above I can only take only ONE user Input. I thought adding the function into a loop so it could work. I am looking for any modification into my code so It can work and so I can take more than one user input.
  • Potential duplicate: stackoverflow.com/questions/8128578/…
  • It is different. I ve seen that link
  • I think that Ben Stern's answer will work also if you just change getUserInput(n+1); to getUserInput(++n);. Also, change the initial call to getUserInput(0) to getUserInput(1) or you'll get 4 inputs because rl.question get's called before n is tested.
  • okay thanks. let me check this. (edit) It looks like its working. thanksss I will keep you updated for the stage of the program ;)
  • Why did this work for the OP and mine didn't? I agree about the off-by-one, but this is functionally equivalent otherwise.
  • You're right, Ben. Your code does work. I don't know why it didn't work for the OP except that it ran 4 times, which might have led to the incorrect assumption that it wasn't working right. I don't think I tried your code before I wrote mine. I just looked at it afterwards and tried to point out to the OP that your approach was a good one.
  • I am checking it rn. Isnt there any easier way to achive this with a loop like I started doing ? Thanks :)
  • As it currently stands, this looks more like a comment than an answer. Providing more information about what "inquirer" does would be helpful to the OP rather than providing just an external link. An example on how it works would also be beneficial.
  • yea actually that's what I am looking for. Maybe any modification on my code would be great. I have been dealing with it for hours And I cant figure it out what the problem is. Thanks
  • Your provided code is not working. It is the same thing. :(
  • This is working for me just fine. Originally, it issued 4 prompts instead of 3, but I fixed that by calling getUserInput with a 1 as suggested above.