Python 嵌套循环打印带星号的矩形 [英] Python Nested Loops To Print Rectangle With Asterisks
本文介绍了Python 嵌套循环打印带星号的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编写嵌套循环来打印一个矩形.给定程序的示例输出:
Write nested loops to print a rectangle. Sample output for given program:
3 颗星:***
3 颗星:***
我试过了,结果是这样的:
I tried it and ended up with this:
num_rows = 2
num_cols = 3
'''IDK WHAT TO PUT HERE'''
print('*', end=' ')
print('')
任何帮助将不胜感激!谢谢!
Any help would be appreciated! Thanks!
推荐答案
给你!试试这个!
num_rows = 2
num_cols = 3
for i in range(num_rows):
print('*', end=' ')
for j in range(num_cols-1):
i*=j
print('*', end=' ')
print('')
这篇关于Python 嵌套循环打印带星号的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文