def greet(c='World'):
print('hello'+','+c)
return
greet()
greet('sb')
print('hello'+','+c)
return
greet()
greet('sb')
2020-10-13
# coding=utf-8
#请分别使用循环和递归的形式定义函数,求出1~100的和。
#循环
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))
#请分别使用循环和递归的形式定义函数,求出1~100的和。
#循环
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
按题目要求,应该是这么写吧
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
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
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print (x + y + z)
print (x + z + y)
print (y + x + z)
print (y + z + x)
print (z + x + y)
print (z + y + x)
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print (x + y + z)
print (x + z + y)
print (y + x + z)
print (y + z + x)
print (z + x + y)
print (z + y + x)
2020-09-30