如果你今天要寫「跳跳繩」...
拿起跳繩 重複 甩繩子 跳起來 停止
拿起跳繩 重複直到 累了 甩繩子 跳起來 停止
拿起跳繩 重複 十次 甩繩子 跳起來 停止
while 條件:
重複執行的指令
其他指令
isTired = False
while isTired == False:
print('Jump!')
isTired = True
print('End')
Jump! End
limit = 3
counts = 0
while counts < limit:
print('Jump!')
counts += 1
print('End')
Jump! Jump! Jump! End
while True:
print('hi~')
print('End')
hi~ hi~ hi~ hi~ hi~ hi~ hi~
for 變數 in 序列:
重複執行的指令
其他指令
scores = [60,70,100]
for x in scores:
print(x)
print('End')
60 70 100 End
str = 'Hello'
for x in str:
print(x)
print('End')
H e l l o End
names_scores = (('Amy',82,90),('John',33,64),('Zoe',91,94))
for x,y,z in names_scores:
print(x)
print(y,z)
print('End')
Amy 82 90 John 33 64 Zoe 91 94 End
請用迴圈計算此班的各科平均與個人總平均
姓名 | C | Python | Java |
---|---|---|---|
習西西 | 80 | 74 | 29 |
王蟒蛇 | 38 | 84 | 59 |
林嘉娃 | 49 | 43 | 78 |
假設我想要一杯紅茶微糖去冰...
函式名稱(參數)
print('Hi~') #Hi~
print('1','2','3') #1 2 3
a = [1,2,3,4,5]
b = len(a) #b = 5
請問下列程式碼執行結果為何?
a='15'
print(a)
print(int(a))
print(float(a))
print(complex(a))
print(bool(a))
b=15
print(bin(b))
print(hex(b))
print(oct(b))
c=97
print(chr(c))
d='a'
print(ord(d))
請問下列程式碼執行結果為何?
a = 3
b = -3
c = 0
d = -0
print(abs(a))
print(abs(b))
print(abs(c))
print(abs(d))
print(max(a,b,c,d))
print(min(a,b,c,d))
e = 2
f = 3
g = 9
h = 0.5
print(pow(e,f))
print(pow(f,e))
print(pow(g,h))
i = 1.4
j = 1.5
k = -0.5
print(round(i))
print(round(j))
print(round(k))
x = [1,2,3,4,5]
total = sum(x)
print(total)
請問下列程式碼執行結果為何?
a = [4,2,1,-3,5]
b = [1,2,3,4,5]
print(len(a))
sorted(a)
print(a)
for x in reversed(a):
print(x,end=' ')
print('\n====================')
for x in range(1,5):
print(x,end=' ')
print('\n====================')
print(list(zip(a,b)))