Python for語句應用

2021-08-22 06:02:33 字數 1661 閱讀 1339

str = "hello"

#字串hello

for n in

str:

print(n,end=" ")

for

numin range(1,101): #1-100

print(num)

n = int(input("請輸入行數:"))

for trigon in

range(n): #range(0,n)

for tri in

range(trigon+1):

print("*",end=" ")

print()

n = int(input("請輸入行數:"))  

for rectangle in range(n):

for rec in range(n):

print("*",end=" ")

print()

for

numin range(1,101):

ifnum%2 == 0: #偶數

print(num)

for

numin range(5,89):

ifnum%2 == 1

andnum%3 == 0: #奇數且能被3整除

print(num)

for i in range(1,10):

for j in range(1,i-1):

print(j,"*",i,"=",(i*j),end="\t")

print()

count = 0

fornum

in range(33,89):

ifnum%2 == 0:

count += 1

#數量+1

print(num)

if count == 20:

break

print(num)

for

numin range(1,51):

ifnum%2 == 0

andnum

<=40:

print(num)

sum=0

#sum為和

for s in range(1,6):

print("請輸入第",s,"個同學的成績")

score = int(input()) #int 數字型別,定義input為數字型別

sum += score

print("這個班的平均成績為:",sum

//5)

for c in range(1,6):

sum = 0

for s in range(1,6):

print("請輸入第",c,"個班第",s,"個同學的成績:")

score = int(input())

sum += score

print("第",c,"個班的平均成績為:",sum//5)

Python for 迴圈語句

python for迴圈可以遍歷任何序列的專案,如乙個列表或者乙個字串。語法 for迴圈的語法格式如下 for iterating var insequence statements s 流程圖 例項 usr bin python coding utf 8 forletterin python 第乙...

Python for 迴圈語句

python for 迴圈語句 python for 迴圈可以遍歷任何序列的專案,如乙個列表或者乙個字串。語法 for迴圈的語法格式如下 for iterating var in sequence statements s 流程圖 例項 usr bin python coding utf 8 for...

Python for 迴圈語句

python for 迴圈語句 python for 迴圈可以遍歷任何序列的專案,如乙個列表或者乙個字串。語法 for迴圈的語法格式如下 for iterating var in sequence statements s 流程圖 例項 usr bin python coding utf 8 for...