使用字母列印 K 的程式
Python 用於在較短時間內輕鬆列印不同模式,以符合使用者需求。同樣的,我們可以使用英語字母列印字母 K。
示例
在此示例中,我們將使用 K 字母建立字母 K。以下是程式碼。
string=""
j = 7
i = 0
for Row in range(0,10):
for Col in range(0,10):
if (Col == 1 or ((Row == Col + 1) and Col != 0)):
string=string+"K"
elif (Row == i and Col == j):
string=string+"K"
i=i+1
j=j-1
else:
string=string+" "
string=string+"\n"
print(string)
輸出
K K K K K K KK K K K K K K K K K K K K K
示例
這是使用英語字母列印字母 K 的另一種方法
def print_k():
print("A A")
print("A A ")
print("A A ")
print("AA ")
print("A A ")
print("A A ")
print("A A")
print_k()
輸出
A A A A A A AA A A A A A A
示例
在此示例中,我們將建立另一種方法來使用字母列印字母 K。
def display(n):
val = n
while ( val >= 0) :
c = 80
for j in range(val + 1):
print( chr ( c + j ), end = " ")
val = val - 1
print()
for i in range(n + 1):
c = 100
for j in range( i + 1):
print( chr ( c + j), end =" ")
print()
n = 8
display(n)
輸出
P Q R S T U V W X P Q R S T U V W P Q R S T U V P Q R S T U P Q R S T P Q R S P Q R P Q P d d e d e f d e f g d e f g h d e f g h i d e f g h i j d e f g h i j k d e f g h i j k l
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP