Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I know that in C++, we can take the user input, but I want to know how can we do that in Python?

Kindly refer to the below code that will take user input in c++

#include<iostream>

using namespace std;

int main() {

    int array[50];

    cin>>n;

    //ask a list

    for(i = 0; i<n; i++){

        cin>>array[i];

    }

}

1 Answer

0 votes
by (108k points)

For your case, it is better to use the input() function that will help you to take user input in Python. The below code will convert numbers separated by spaces to be stored in ar variable:

ar = list(map(int, input().strip().split(' ')))

Related questions

0 votes
1 answer
asked Dec 8, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 11, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
asked Jul 9, 2020 in Python by ashely (50.2k points)

Browse Categories

...