为了账号安全,请及时绑定邮箱和手机立即绑定

最赞回答 / qq_慕粉4217309
num = 5while True:    if num >= 90:        break    num = num + 2print(num)来试试这个

最赞回答 / qq_慕粉4217309
L = [95.5, 85, 59, 66, 72]L.sort()print(L)print(L[-3:5])这样就好了,因为【:】是从左往右看的
def sub_sum(L):
result_odd=[]
result_even=[]
for i in L:
if i%2==1:
result_odd.append(i)
else:
result_even.append(i)
return sum(result_odd),sum(result_even)
L = [1, 3, 5, 7, 9]
print(sub_sum(L))
def square_of_sum(L):
result=0
for i in L:
result=result+i*i
return result
L = [1, 3, 5, 7, 9, 11]
print(square_of_sum(L))
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
same=[]
print(s1.isdisjoint(s2))
for i in s1:
for j in s2:
if i==j:
same.append(i)
print(same)
s=1
a=1
while s<=10:
a = a * s
s = s + 1
print(a)
a是字符所以a=True,所以a or 'world'=a 根据与运算法则返回world结果是hello,python
b是空字符串所以b=False,所以b or 'world'根据or运算法返回world,所以结果是hello,world
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
S.remove(i)
else:
S.add(i)
print(S)
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names_set = set(names)
print(names_set)
x="alice"
for i in names_set:
if x.capitalize()==i:
print("True")
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for i in d:
for j in d[i]:
print(i,j)
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
print(d.items())

for i,value in d.items():
print(i,value)

最赞回答 / weixin_精慕门7014924
sum是你可以自己指定的变量(它甚至可以不叫sum,只要是其他任意符合python命名规范的变量名都可以)。在求和时,因为0加上任何数都不会改变其值,所以将sum设置为0是可行的(当然设置为1也是可行的,得到的结果是一样的);在求乘积时,当然不可以乘0,所以就直接设sum的初始值为1啦。一句话概括,就是你想让sum是什么值它就可以是什么值,只要保证结果正确。
# Enter a code
count = 10;
this_num = 0;
while this_num < count:
print(this_num)
this_num+=1
# Enter a code
L = [[75, 92, 59, 68, 99],[8, 2, 6, 4, 8],[715, 952, 589, 698, 919]]
for data in L:
for num in data:
print(num)
# coding: utf-8
kscj=58
if kscj < 60:
print('不及格')
elif kscj >= 60 and kscj <80 :
print("及格")

elif kscj >= 80 and kscj <90:
print("优秀!")
elif kscj >= 90 :
print("顶尖!")
# coding: utf-8
age = 16
if age>18:
print("恭喜你成年了!")
else:
print("小朋友未成年哦!!")
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作,灵活使用流程控制语句。

微信扫码,参与3人拼团

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消