Viết một chương trình Python để tìm các số tối đa và tối thiểu từ các số thập phân được chỉ định. Giải pháp mẫu:-:- Mã Python: Đầu ra mẫu: Trình bày bằng hình ảnh: Flowchart: Trình chỉnh sửa mã Python: Có một cách khác để giải quyết giải pháp này? Đóng góp mã của bạn [và nhận xét] thông qua Disqus. Trước đây: Viết chương trình Python để chuyển đổi tọa độ cực sang tọa độ hình chữ nhật. Write a Python program to convert Polar coordinates to rectangular coordinates.Toán Python: Bài tập-36 với giải pháp
from decimal import *
data = list[map[Decimal, '2.45 2.69 2.45 3.45 2.00 0.04 7.25'.split[]]]
print["Maximum: ", max[data]]
print["Minimum: ", min[data]]
Maximum: 7.25
Minimum: 0.04
Next: Write a Python program to find the sum of the following decimal
numbers and display the numbers in sorted order.
Mức độ khó của bài tập này là gì?
Kiểm tra kỹ năng lập trình của bạn với bài kiểm tra của W3Resource.
Python: Lời khuyên trong ngày
Tìm chỉ mục của một mục trong danh sách:
>>> x = ["foo", "bar", "baz"] >>> x.index["bar"] 1
- Bài tập: Top 16 chủ đề phổ biến nhất hàng tuần
- Bài tập SQL, Thực hành, Giải pháp - Tham gia
- Bài tập SQL, Thực hành, Giải pháp - Quan sát phụ
- JavaScript Basic - Bài tập, Thực hành, Giải pháp
- Java Array: Bài tập, Thực hành, Giải pháp
- C Bài tập lập trình, Thực hành, Giải pháp: Tuyên bố có điều kiện
- Cơ sở dữ liệu nhân sự - Sắp xếp bộ lọc: Bài tập, Thực hành, Giải pháp
- C Bài tập lập trình, Thực hành, Giải pháp: Chuỗi
- Các loại dữ liệu Python: Từ điển - Bài tập, Thực hành, Giải pháp
- Câu đố lập trình Python - Bài tập, Thực hành, Giải pháp
- Mảng C ++: Bài tập, Thực hành, Giải pháp
- Báo cáo và vòng lặp có điều kiện JavaScript - Bài tập, Thực hành, Giải pháp
- Thuật toán cơ bản C# Sharp: Bài tập, Thực hành, Giải pháp
- Python Lambda - Bài tập, Thực hành, Giải pháp
- Python Pandas DataFrame: Bài tập, Thực hành, Giải pháp
- Công cụ chuyển đổi
- JavaScript: HTML Mẫu xác thực
Bài viết này mang đến cho bạn một chức năng rất thú vị và ít được biết đến của Python, cụ thể là Max [] và Min []. Bây giờ khi so sánh với đối tác C ++ của họ, chỉ cho phép hai đối số, quá nghiêm ngặt là nổi, int hoặc char, các chức năng này không chỉ giới hạn ở 2 yếu tố, mà còn có thể giữ nhiều yếu tố như đối số và cũng hỗ trợ các chuỗi trong các đối số của chúng, từ đó Cho phép hiển thị chuỗi nhỏ nhất hoặc lớn nhất về mặt từ vựng. Chức năng chi tiết được giải thích dưới đây. & NBSP;not only limited to 2 elements, but can hold many elements
as arguments and also support strings in their arguments, hence allowing to display lexicographically smallest or largest string as well. Detailed functionality are explained below.
Hàm này được sử dụng để tính toán tối đa các giá trị được truyền trong đối số của nó và giá trị lớn nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
Syntax : max[a,b,c,..,key,default] Parameters : a,b,c,.. : similar type of data. key : key function where the iterables are passed and comparison is performed default : default value is passed if the given iterable is empty Return Value : Returns the maximum of all the arguments. Exceptions : Returns TypeError when conflicting types are compared.
Python3
Maximum: 7.25 Minimum: 0.040
Maximum: 7.25 Minimum: 0.041
Maximum: 7.25 Minimum: 0.042
Maximum: 7.25 Minimum: 0.043
Maximum: 7.25 Minimum: 0.044
Maximum: 7.25 Minimum: 0.045
Is
Đầu ra: & nbsp; & nbsp;
Maximum of 4,12,43.3,19 and 100 is : 100
Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
Syntax : min[a,b,c,.., key,default] Parameters : a,b,c,.. : similar type of data. key : key function where the iterables are passed and comparison is performed default : default value is passed if the given iterable is empty Return Value : Returns the minimum of all the arguments. Exceptions : Returns TypeError when conflicting types are compared.
Python3
Maximum: 7.25 Minimum: 0.040
Maximum: 7.25 Minimum: 0.041
Syntax : max[a,b,c,..,key,default] Parameters : a,b,c,.. : similar type of data. key : key function where the iterables are passed and comparison is performed default : default value is passed if the given iterable is empty Return Value : Returns the maximum of all the arguments. Exceptions : Returns TypeError when conflicting types are compared.2
Maximum: 7.25 Minimum: 0.043
Maximum: 7.25 Minimum: 0.044
Maximum: 7.25 Minimum: 0.045
Is
Đầu ra: & nbsp; & nbsp;
Minimum of 4,12,43.3,19 and 100 is : 4
Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
IsThese functions throw TypeError when conflicting data types are compared.
Python3
Maximum: 7.25 Minimum: 0.040
Maximum: 7.25 Minimum: 0.041
Syntax : min[a,b,c,.., key,default] Parameters : a,b,c,.. : similar type of data. key : key function where the iterables are passed and comparison is performed default : default value is passed if the given iterable is empty Return Value : Returns the minimum of all the arguments. Exceptions : Returns TypeError when conflicting types are compared.2
Maximum: 7.25 Minimum: 0.043
Maximum: 7.25 Minimum: 0.044
Maximum: 7.25 Minimum: 0.045
Ngoại lệ
Đầu ra: & nbsp; & nbsp;
Minimum of 4,12,43.3,19 and GeeksforGeeks is :
Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
Traceback [most recent call last]: File "/home/b5da1d7f834a267f94fbbefe1b31a83c.py", line 7, in print [min[ 4,12,43.3,19,"GeeksforGeeks" ] ] TypeError: unorderable types: str[] < int[]
Is
Ngoại lệlexicographically largest and smallest of Strings i.e String appearing first in dictionary or last.
Python3
Maximum: 7.25 Minimum: 0.040
Maximum: 7.25 Minimum: 0.041
Minimum of 4,12,43.3,19 and GeeksforGeeks is :2
Maximum: 7.25 Minimum: 0.043
Maximum: 7.25 Minimum: 0.044
Maximum: 7.25 Minimum: 0.045
1. Kiểu hàng hóa: Các chức năng này ném loại khi so sánh các loại dữ liệu xung đột. & NBSP;
Maximum: 7.25 Minimum: 0.040
Maximum: 7.25 Minimum: 0.041
The word occurring 1st in dict. among given is : algorithm The word occurring last in dict. among given is : programming0
Maximum: 7.25 Minimum: 0.043
Maximum: 7.25 Minimum: 0.044
Maximum: 7.25 Minimum: 0.045
Is
Đầu ra: & nbsp; & nbsp;
The word occurring 1st in dict. among given is : algorithm The word occurring last in dict. among given is : programming
Lỗi thời gian chạy: & nbsp; & nbsp;Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you
want to share more information about the topic discussed above.