日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python中的简单图案打印程序

發布時間:2025/3/11 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python中的简单图案打印程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Pattern 1:

模式1:

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

Code:

碼:

for row in range (0,5):for column in range (0, row+1):print ("*", end="")# ending rowprint('\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 operationfor column in range(0,row+1):print("1 ",end="")# ending lineprint('\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 operationfor column in range (0, row+1):print(n, end=" ")n = n+1# ending lineprint('\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 operationfor column in range (0, row+1):print(n, end=" ")n = n+1# ending lineprint('\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 operationfor column in range (0, row+1):c = chr(n)print(c, end=" ")n = n+1# ending lineprint('\r')

Practice more python experiences here: python programs

在這里練習更多python經驗: python程序

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

總結

以上是生活随笔為你收集整理的Python中的简单图案打印程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。