def data_of_square(side):
C= 4*side
S=side * side
print('c is {},s is {}'.format(C,S))
return C,S
C,S= data_of_square(6)
print('周长={}'.format(C))
print('面积={}'.format(S))
C= 4*side
S=side * side
print('c is {},s is {}'.format(C,S))
return C,S
C,S= data_of_square(6)
print('周长={}'.format(C))
print('面积={}'.format(S))
2020-10-19
# coding=utf-8
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
template = "{}的第{}次成绩是{}分"
for key, value in d.items():
for index in range(len(value)):
print(template.format(key,index+1,value[index]))
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
template = "{}的第{}次成绩是{}分"
for key, value in d.items():
for index in range(len(value)):
print(template.format(key,index+1,value[index]))
2020-10-18
a = 'python'
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
a为有效字符串,即为true; 则 = true
b为空字符串,即为false; 则 = false
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
a为有效字符串,即为true; 则 = true
b为空字符串,即为false; 则 = false
2020-10-15
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