Pattern 1:

模式1:

*
*  *
*  *  *
*  *  *  *
*  *  *  *  *

Code:

码:

for row in range (0,5):
for column in range (0, row+1):
print ("*", end="")
# ending row
print('\r')

Pattern 2:

模式2:

Now if we want to print numbers or alphabets in this pattern then we need to replace the * with the desired number you want to replace. Like if we want pattern like,

现在,如果要在此模式下打印数字或字母,则需要将*替换为要替换的所需数字。 就像我们想要图案一样

1
1  1
1  1  1
1  1  1  1
1  1  1  1  1

Code:

码:

#row operation
for row in range(0,5):
# column operation
for column in range(0,row+1):
print("1 ",end="")
# ending line
print('\r')

Pattern 3:

模式3:

If want increasing numbers in this pattern like,

如果要以这种模式增加数字,

1
1  2
1  2  3
1  2  3  4
1  2  3  4  5

Here we need to declare a starting number from which the patter will start. In the above case the number is starting from 1. So, here we have to create a variable and assigns its value to 1 then we need to print only the value of variable.

在这里,我们需要声明一个起始编号,从该起始编号开始。 在上述情况下,数字从1开始。因此,这里我们必须创建一个变量并将其值分配为1,然后只需要打印变量的值即可。

As its value is increasing every row by 1, but starting value is always 1.

由于其值每行增加1,但起始值始终为1。

So, for that we have to declare the value of the starting number before column operation (second for loop) and need to increase it by 1 after the column operation section after the printing value.

因此,为此,我们必须在列运算之前声明起始编号的值(循环的第二个),并且需要在打印值后的列运算部分之后将起始编号增加1。

Code:

码:

#row operation
for row in range (0, 5):
n = 1
# column operation
for column in range (0, row+1):
print(n, end=" ")
n = n+1
# ending line
print('\r')

Pattern 4:

模式4:

1
2 3
4 5 6
7 8 9 10
11 12 13 14

To get the above pattern only we have to declare the variable before the row operation. Follow the code below,

为了获得上述模式,我们只需要在行操作之前声明变量。 请遵循以下代码,

Code:

码:

n = 1
#row operation
for row in range (0, 5):
# column operation
for column in range (0, row+1):
print(n, end=" ")
n = n+1
# ending line
print('\r')

Pattern 5:

模式5:

A
A  B
A   B  C
A  B  C  D
A  B  C  D  E

The above pattern can also be another type.

上面的模式也可以是其他类型。

For that should have the knowledge of ASCII values of 'A'.

为此,应具有ASCII值 “ A”的知识。

Its ASCII value is 65.

其ASCII值为 65。

In column operation We have to convert the ASCII value to character using chr() function.

在列操作中,我们必须使用chr()函数将ASCII值转换为字符。

Code:

码:

#row operation
for row in range (0, 5):
n = 65
# column operation
for column in range (0, row+1):
c = chr(n)
print(c, end=" ")
n = n+1
# ending line
print('\r')

Practice more python experiences here: python programs

在这里练习更多python经验: python程序

翻译自: https://www.includehelp.com/python/simple-pattern-printing-programs.aspx

Python中的简单图案打印程序相关推荐

  1. Python中yield简单用法

    Python中yield简单用法 你或许知道带有yield的函数在Python中被称之为generator,那何为 generator? 我们暂时抛开generator,先从一个常见编程题目开始,循序 ...

  2. python使用spark_如何在Python中编写简单代码,并且速度超越Spark?

    全文共3482字,预计学习时长7分钟 如今,大家都在Python工具(pandas和Scikit-learn)的简洁性.Spark和Hadoop的可扩展性以及Kubernetes的操作就绪之间做选择. ...

  3. python 字节流分段_如何在Python中编写简单代码,并且速度超越Spark?

    全文共 3482字,预计学习时长 7分钟 如今,大家都在Python工具(pandas和Scikit-learn)的简洁性.Spark和Hadoop的可扩展性以及Kubernetes的操作就绪之间做选 ...

  4. python 怎么打印数组_?怎么将python中的数组全部打印出来array

    python array list 1,3似乎不遍历循环是不行滴~ python中的list和array的不同之处 上面正解 python的numpy中合并array 你好: 你用append()是函 ...

  5. 如何在 Python 中以表格格式打印列表?

    在 Python 中,列表是一种常见的数据结构,用于存储和组织数据.当我们需要将列表的内容以表格形式展示时,可以通过特定的方法和技巧来实现.本文将详细介绍如何在 Python 中以表格格式打印列表,以 ...

  6. 如何在 Python 中构建跨平台桌面应用程序

    如何在 Python 中构建跨平台桌面应用程序 开发桌面 GUI 应用程序曾经是一个乏味.容易出错且缓慢的过程. 当然,Python 在整体上极大地简化了应用程序开发,但在 GUI 领域,仍然没有真正 ...

  7. 五分钟理解yield在python中的简单用法,让你不再迷惑

    很多同学无论是在学习python还是使用python的过程中,都会遇到yield关键字,这个让人头大的问题,今天,就给大家分享一下我自学yield的心路历程 基本概念: (1)在 Python 中,使 ...

  8. python写小程序-用python写个简单的小程序,编译成exe跑在win10上

    每天的工作其实很无聊,早知道应该去IT公司闯荡的.最近的工作内容是每逢一个整点,从早7点到晚11点,去查一次客流数据,整理到表格中,上交给素未蒙面的上线,由他呈交领导查阅. 人的精力毕竟是有限的,所以 ...

  9. python编写加密程序_用Python实现一个简单的加密程序

    生活中,有时候我们需要对一些重要的文件进行加密,Python 提供了诸如 hashlib,base64 等便于使用的加密库. 对于日常学习而言,我们可以借助异或操作,实现一个简单的文件加密程序,从而强 ...

最新文章

  1. Ubuntu Linux配置Nginx+MySQL+PHP+phpMyAdmin详细步骤
  2. vue生命周期大白话篇
  3. 你试过不用if撸代码吗?
  4. c语言 整型转bool,C语言的布尔类型(_Bool)【转】
  5. 另辟蹊径:从其他角度去解决数据库问题
  6. 【推荐实践】阿里飞猪“猜你喜欢”推荐排序实践
  7. 四个角不是直角的四边形_同步资料人教版四上数学第五单元平行四边形和梯形5.1...
  8. 2019年最流行的50款开源软件
  9. 关于WordCount的作业
  10. mysql 数据库取前后几秒 几分钟 几小时 几天的语句
  11. L. Leverage MDT
  12. P1195口袋的天空
  13. “消失”的Android技术博主们现在如何!Android开发者前路在哪?
  14. UndoManager教程
  15. vue 路由懒加载,使用 import 无法处理
  16. malloc申请堆内存
  17. 遮天 | 实战绕过卡巴斯基、Defender上线CS和MSF及动态命令执行...
  18. 实现Gmail邮箱翻转效果之开篇
  19. 该文件没有与之关联的应用...的解决方法
  20. HCIP第十七天笔记

热门文章

  1. java方法的参数类型_Java 基础 14 方法的重载 与 方法参数类型详解
  2. mysql 优化代码_MySQL Order by 语句优化代码详解
  3. PWA将带来新一轮大前端技术洗牌?
  4. C++将地址转换为字符串
  5. Angular深入理解基本组成
  6. Poor God Water【矩阵快速幂】
  7. python isinstance()
  8. hadoop namenode管理元数据机制
  9. 路由器DHCP和DHCP中继的配置
  10. android shape.xml 属性详解