用Python根据row值打印左下角三角形,右下角三角形,等腰三角形
时间: 2023-04-01 13:01:56 浏览: 113
左下角三角形:
```python
n = int(input("请输入行数:"))
for i in range(1, n+1):
for j in range(1, i+1):
print("*", end="")
print()
```
右下角三角形:
```python
n = int(input("请输入行数:"))
for i in range(1, n+1):
for j in range(1, n-i+1):
print(" ", end="")
for j in range(1, i+1):
print("*", end="")
print()
```
等腰三角形:
```python
n = int(input("请输入行数:"))
for i in range(1, n+1):
for j in range(1, n-i+1):
print(" ", end="")
for j in range(1, 2*i):
print("*", end="")
print()
```
注意:以上代码仅供参考,可能存在错误或不完善之处。
相关问题
用Python根据triangle (row)函数打印左下角三角形,右下角三角形,等腰三角形
左下角三角形:
```
def triangle(n):
for i in range(n):
for j in range(i+1):
print("*", end="")
print()
triangle(5)
```
右下角三角形:
```
def triangle(n):
for i in range(n):
for j in range(n-i-1):
print(" ", end="")
for j in range(i+1):
print("*", end="")
print()
triangle(5)
```
等腰三角形:
```
def triangle(n):
for i in range(n):
for j in range(n-i-1):
print(" ", end="")
for j in range(2*i+1):
print("*", end="")
print()
triangle(5)
```
用Python根据row值打印三个三角形
非常感谢您的提问。以下是Python代码,可以根据row值打印三个三角形:
```
row = 5
# 打印正三角形
for i in range(row):
print(' ' * (row - i - 1) + '*' * (2 * i + 1))
# 打印倒三角形
for i in range(row):
print(' ' * i + '*' * (2 * (row - i) - 1))
# 打印等腰三角形
for i in range(row):
print(' ' * (row - i - 1) + '*' * (2 * i + 1))
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)