Sử dụng hàm map [] và chức năng chia [] để lấy n số lượng đầu vào trong python. Nếu các số được cung cấp trong cùng một dòng thì bạn có thể sử dụng, Nếu đầu vào ở các dòng khác nhau thì, Mã ví dụ đơn giản. Output::list[map[int, input[].split[][:N]]]
arr = list[map[int, input[].split[]]]
arr = [ int[input[]] for i in range[n]]
arr = list[map[int, input[].split[]]]
print[arr]
Nếu người dùng muốn chọn có bao nhiêu số muốn nhập
n = int[input["Enter number of elements : "]]
# Below line read inputs from user using map[] function
a = list[map[int, input["\nEnter the numbers : "].strip[].split[]]][:n]
print["\nList is - ", a]
Đầu ra::
Nhập số phần tử: 2
Nhập số: 1 2
Danh sách là - [1, 2]
Hãy bình luận nếu bạn có bất kỳ nghi ngờ hoặc đề xuất nào về chủ đề đầu vào Python này.
Lưu ý: IDE: & NBSP; Pycharm & NBSP; 2021.3.3 [Phiên bản cộng đồng] IDE: PyCharm 2021.3.3 [Community Edition]
Windows 10
Python 3.10.1
Tất cả & nbsp; ví dụ python & nbsp; là trong & nbsp; Python & nbsp; 3, vì vậy có thể khác với các phiên bản Python 2 hoặc nâng cấp. Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Bằng cấp về Khoa học máy tính và Kỹ sư: Nhà phát triển ứng dụng và có nhiều ngôn ngữ lập trình kinh nghiệm. Sự nhiệt tình cho công nghệ và thích học kỹ thuật.
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luận
Trong bài đăng này, chúng ta sẽ xem làm thế nào để lấy đầu vào số nguyên trong Python. Như chúng ta biết rằng hàm đầu vào tích hợp [] Python luôn trả về đối tượng lớp STR [Chuỗi]. Vì vậy, để lấy đầu vào số nguyên, chúng ta phải gõ các đầu vào đó vào số nguyên bằng cách sử dụng hàm int int [] tích hợp python.
Python3
Hãy cho chúng tôi xem các ví dụ:
arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
4arr = list[map[int, input[].split[]]]
5arr = list[map[int, input[].split[]]]
6Ví dụ 1:
arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
4arr = list[map[int, input[].split[]]]
5arr = list[map[int, input[].split[]]]
6Output:
100
input_a
____10
1arr = list[map[int, input[].split[]]]
2arr = list[map[int, input[].split[]]]
Python3
Hãy cho chúng tôi xem các ví dụ:
arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
4arr = list[map[int, input[].split[]]]
5arr = list[map[int, input[].split[]]]
6Ví dụ 1:
arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
4arr = list[map[int, input[].split[]]]
51002
Output:
10 20
Ví dụ 3:
Python3
1003
arr = list[map[int, input[].split[]]]
0 arr = list[map[int, input[].split[]]]
11006
arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
41009
10 200
10 201
arr = list[map[int, input[].split[]]]
0arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
41009
10 20 30 40 50 60 70 array: ['10', '20', '30', '40', '50', '60', '70'] 10 20 30 40 50 60 70 array: [10, 20, 30, 40, 50, 60, 70]4
Output:
10 20 30 40 50 60 70 array: ['10', '20', '30', '40', '50', '60', '70'] 10 20 30 40 50 60 70 array: [10, 20, 30, 40, 50, 60, 70]
Ví dụ 4:
Python3
10 20 30 40 50 60 70 array: ['10', '20', '30', '40', '50', '60', '70'] 10 20 30 40 50 60 70 array: [10, 20, 30, 40, 50, 60, 70]5
arr = list[map[int, input[].split[]]]
0 arr = list[map[int, input[].split[]]]
9arr = list[map[int, input[].split[]]]
4arr = list[map[int, input[].split[]]]
1arr = list[map[int, input[].split[]]]
4Enter the size of list : 4 Enter the integer elements of list[Space-Separated]: 6 3 9 10 The list is: [6, 3, 9, 10]1
Enter the size of list : 4 Enter the integer elements of list[Space-Separated]: 6 3 9 10 The list is: [6, 3, 9, 10]2
Enter the size of list : 4 Enter the integer elements of list[Space-Separated]: 6 3 9 10 The list is: [6, 3, 9, 10]3
arr = list[map[int, input[].split[]]]
0 Enter the size of list : 4 Enter the integer elements of list[Space-Separated]: 6 3 9 10 The list is: [6, 3, 9, 10]5
arr = list[map[int, input[].split[]]]
4______77714arr = list[map[int, input[].split[]]]
9arr = [ int[input[]] for i in range[n]]
0arr = list[map[int, input[].split[]]]
1arr = [ int[input[]] for i in range[n]]
3arr = [ int[input[]] for i in range[n]]
4arr = [ int[input[]] for i in range[n]]
5
arr = list[map[int, input[].split[]]]
3arr = list[map[int, input[].split[]]]
4arr = [ int[input[]] for i in range[n]]
8arr = [ int[input[]] for i in range[n]]
9Output:
Enter the size of list : 4 Enter the integer elements of list[Space-Separated]: 6 3 9 10 The list is: [6, 3, 9, 10]