Hướng dẫn how do you make a rectangular pattern in python? - Làm thế nào để bạn tạo ra một mô hình hình chữ nhật trong con trăn?
Show
Trong bức ảnh này, chúng ta sẽ thảo luận về cách tạo một mẫu hình chữ nhật bằng cách sử dụng các ngôi sao trong Python. Nhiều mẫu có thể được in bằng Python, một khi chúng ta có một sự kìm kẹp mạnh mẽ đối với các khái niệm liên quan đến các vòng lặp. Ở đây chúng tôi sẽ sử dụng các vòng Sự mô tảĐể thực hiện một mẫu hình chữ nhật bằng lập trình Python, chúng tôi sẽ sử dụng 2 vòng lặp
Mã sốHãy cùng nhìn vào đoạn mã bên dưới.
Giải trình
Người đóng góp Vinisha Maheshwari 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 Examples: Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@ Bàn luận C++Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************0 Cho chiều cao H và chiều rộng W, in một mẫu hình chữ nhật như trong ví dụ dưới đây. Ý tưởng là chạy hai vòng. Một cho số lượng hàng được in và một cho số lượng cột. Chỉ in ‘@@chỉ khi hàng hiện tại là đầu tiên hoặc cuối cùng. Hoặc cột hiện tại là đầu tiên hoặc cuối cùng. & Nbsp; 0 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************1 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************2 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************3 1 0 8 9 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@0 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************4 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************5 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************7 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************9 8 0 1 for 3 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 5 @@@@@ @ @ @ @ @@@@@2 @@@@@ @ @ @ @ @@@@@3 @@@@@ @ @ @ @ @@@@@4 9 @@@@@ @ @ @ @ @@@@@6 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 @@@@@ @ @ @ @ @@@@@9 @@@@@ @ @ @ @ @@@@@4 9 for 2Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 8 for 51 for 5
8 for 3 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@6
Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 @@@@@ @ @ @ @ @@@@@0 @@@@@ @ @ @ @ @@@@@1 1 for 6Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 for 0
# Initialising Length and Breadthrows = 3columns = 6# Loop through number of rowsfor i in range(rows): # Loop through number of columns for j in range(columns): # Printing Pattern print('*', end = ' ') print()1Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************ 6 for41 for 8 for 9Java 1 0
8 0 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 print() 31 for 4 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************4 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************5 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************7 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************9 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 0 8 for 3 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 for 7for 8for 9Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 for 3 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 print() 8for 8Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************00 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************16 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************17 @@@@@ @ @ @ @ @@@@@6 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************19 @@@@@ @ @ @ @ @@@@@2 @@@@@ @ @ @ @ @@@@@9 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************16 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************17 for 2Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************19 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 for 58 for 51 for 5@@@@@ @ @ @ @ @@@@@2 @@@@@ @ @ @ @ @@@@@0 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************05 for 81 for 1Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************10 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************11 for 8 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************13 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************08 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************15 8 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************47 1 for 5
Python31 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************33 for 4 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************4 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************36 8 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************6 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************41 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************42 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************43 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************44 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************51 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************52 1 for Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************55 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************56 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************57 3 for 8Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************60 8 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************62 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************63 @@@@@ @ @ @ @ @@@@@2 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************62 3 @@@@@ @ @ @ @ @@@@@6 02 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************75 04 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 @@@@@ @ @ @ @ @@@@@9 07 @@@@@ @ @ @ @ @@@@@2 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************62 3 for 202 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************75 04 15 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************75 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************42 18 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************75 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************44 21 PHP22 23 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************5 25 26 27 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************15 0 1 for 3 33 34 33 1 0 8 44 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@0 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 8 for 3 50 34 50 8 0 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 @@@@@ @ @ @ @ @@@@@0 3 33 64___ @@@@@ @ @ @ @ @@@@@2 50 64 50 66 27 ____275 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 44 @@@@@ @ @ @ @ @@@@@6 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 @@@@@ @ @ @ @ @@@@@9 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@9 44 for 2Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@1 8 for 51 for 5
1 25 93 1 27 96 1 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************5 25 26 27 Enter number of rows: 4 Enter number of columns: 12 Rectangular pattern is: ************ ************ ************ ************19 Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@03 Đầu ra @@@@@ @ @ @ @ @@@@@
Bài viết này được đóng góp bởi Anurag Rawat. Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeekSforGeek.org hoặc gửi bài viết của bạn. Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên máy tính khác.Anurag Rawat. 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. Vui lòng viết nhận xét nếu bạn tìm thấy bất cứ điều gì không chính xác hoặc nếu bạn muốn chia sẻ thêm thông tin về chủ đề được thảo luận ở trên. Làm thế nào để bạn in một hình chữ nhật trong Python?long = int (input ("longueur:")) larg = int (input ("lớn:")) cho i trong phạm vi (dài): if (i == 0) hoặc (i == dài - 1): # #Kiểm tra xem nó là bản in đầu tiên hay cuối cùng ('*'* larg) # in toàn bộ hàng không có khoảng cách khác: # cho các hàng giữaHàng có khoảng cách ở giữa.
Làm thế nào để bạn tạo ra một mô hình trong Python?Các bước để in mẫu trong Python.. Quyết định số lượng hàng và cột.Có một cấu trúc điển hình để in bất kỳ mẫu nào, tức là số lượng hàng và cột..... Lặp lại hàng..... Lặp lại các cột..... In ngôi sao hoặc số..... Thêm dòng mới sau mỗi lần lặp của vòng lặp bên ngoài .. Làm thế nào để bạn in một mẫu rỗng trong Python?Đầu ra: Mô hình hình chữ nhật rỗng.. In 1-10-101-1010 Mẫu số .. In 0-01-010-0101 Mẫu số nhị phân .. In 1-101-10101 Kim tự tháp số nhị phân .. 1-10-101-1010 Mẫu .. |