def greet(c='World'):
print('hello'+','+c)
return
greet()
greet('sb')
print('hello'+','+c)
return
greet()
greet('sb')
2020-10-13
# coding=utf-8
#請分別使用循環(huán)和遞歸的形式定義函數,求出1~100的和。
#循環(huán)
def sum(n):
i=0
s=0
while i<=n:
s=s+i
i=i+1
print(s)
return
sum(100)
#遞歸
def he(n):
x=0
if n==1:
x=n
else:
x=he(n-1)+n
return x
print(he(100))
#請分別使用循環(huán)和遞歸的形式定義函數,求出1~100的和。
#循環(huán)
def sum(n):
i=0
s=0
while i<=n:
s=s+i
i=i+1
print(s)
return
sum(100)
#遞歸
def he(n):
x=0
if n==1:
x=n
else:
x=he(n-1)+n
return x
print(he(100))
2020-10-13
# coding=utf-8
def sub_sum(L):
y=0
j=0
i=0
while i<len(L):
if i%2==0:
y=y+L[i]
else:
j=j+L[i]
i=i+1
print(y,j)
return
sub_sum([1,2,3,4])
def sub_sum(L):
y=0
j=0
i=0
while i<len(L):
if i%2==0:
y=y+L[i]
else:
j=j+L[i]
i=i+1
print(y,j)
return
sub_sum([1,2,3,4])
2020-10-13
最新回答 / 慕函數0346336
?# -*- coding: utf-8 -*d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}for key, value in d.items():? ? n=1? ? for score in value:? ? ? ? print('{}的第{}次成績是{}'.format(key, n, score))? ? ? ? n = n+1
Bob的第...
2020-10-13
按題目要求,應該是這么寫吧
L = [95.5, 85, 59, 66, 72]
L2 = sorted(L,reverse=True)
print(L2[0:3])
L = [95.5, 85, 59, 66, 72]
L2 = sorted(L,reverse=True)
print(L2[0:3])
2020-10-10
最贊回答 / 慕標7081267
<...code...>name = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']score = [89, 72, 88, 79, 99]scores = [89, 72, 88, 79, 99]score.sort(reverse = True)rank = []for i in range(len(score)):? ? for j in range(len(score)):? ? ? ? if score[i] == scores[...
2020-10-09
最新回答 / mixuelantang
短路計算。真 and? 假 總是輸出假,所以True and 0輸出0,你也說了False和0等價,所以輸出0和輸出False等價。假 or 真 總是輸出真,是指輸出真的那個語句,如果先賦值a = False, 0 or a 則輸出False即a 的值
2020-10-08
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for key, name in zip(d.keys(), names):
if name in d.keys():
print(d.get(key))
else:
print(None)
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for key, name in zip(d.keys(), names):
if name in d.keys():
print(d.get(key))
else:
print(None)
2020-10-03
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
score = [89, 72, 88, 79, 99]
for j in range(len(score)):
for i in range(len(names) - 1):
if score[i] > score[i + 1]:
temp = names[i]
names[i] = names[i + 1]
names[i + 1] = temp
print(names)
score = [89, 72, 88, 79, 99]
for j in range(len(score)):
for i in range(len(names) - 1):
if score[i] > score[i + 1]:
temp = names[i]
names[i] = names[i + 1]
names[i + 1] = temp
print(names)
2020-10-03
length =3.14
width=1.57
result=round(length*width)
print(result)
不用加變量類型和分號,簡單的有點不習慣
width=1.57
result=round(length*width)
print(result)
不用加變量類型和分號,簡單的有點不習慣
2020-09-30