Python nhỏ nhất đến lớn nhất
Xin chào mọi người, đây là chương trình Python tìm ra số nhỏ nhất và lớn nhất trong danh sách Số nhỏ nhất và lớn nhất trong danh sách — lập trình trong python. comỞ đây chúng tôi sử dụng 2 hàm được xác định trước min() và max() để kiểm tra số nhỏ nhất và lớn nhất trong danh sách tương ứng Vì, không giống như các ngôn ngữ lập trình khác, Python không có mảng, thay vào đó, nó có danh sách. Sử dụng danh sách dễ dàng và thoải mái hơn khi làm việc so với mảng. Hơn nữa, các chức năng sẵn có rộng lớn của Python, giúp công việc trở nên dễ dàng hơn. Vì vậy, bằng cách sử dụng các kỹ thuật này, hãy thử tìm các phạm vi khác nhau của số trong một danh sách nhất định. ví dụ
Khuyến khích. Vui lòng thử cách tiếp cận của bạn trên {IDE} trước, trước khi chuyển sang giải pháp Cách tiếp cận số 1. Cách tiếp cận đơn giản. Python cho phép chúng ta sắp xếp danh sách bằng hàm list(). Sử dụng điều này, chúng ta có thể tìm thấy các dãy số khác nhau trong một danh sách, từ vị trí của chúng, sau khi được sắp xếp. Giống như vị trí đầu tiên phải chứa phần tử nhỏ nhất và phần tử cuối cùng phải là phần tử lớn nhất. Python3
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 40 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 41
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 43
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 45_______0_______6 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 47 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 48 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 49 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 40_______0_______1
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 45_______0_______6 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 45 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 46 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 47 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 41
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 45_______0_______6 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 42 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 48 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 49 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 45 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 41
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 46 Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 40_______0_______1
Largest element is: 45 Smallest element is: 2 Second Largest element is: 41 Second Smallest element is: 45 # Python prog to illustrate the following in a list 9def 4# Python prog to illustrate the following in a list 9def 6# Python prog to illustrate the following in a list 9def 8# Python prog to illustrate the following in a list 9find_len(list1): 0_______29_______9_______31_______2_______39_______5 |