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

初识Python

廖雪峰 移动开发工程师
难度入门
时长 5小时 0分
学习人数
综合评分9.43
3762人评价 查看评价
9.7 内容实用
9.4 简洁易懂
9.2 逻辑清晰
s = 'Python was started in 1989 by "Guido". \n Python is free and easy to learn.'
print s
x1 = 1
d = 3
n = 100
x100 = x1+n*d
s = n*x1+n*(n-1)*d/2
print s
sum = 0
x = 1
while x<=100:
x=x+2
sum+=x
print sum
我写错了,都能过····
sum = 0
x = 1
while x<100 && x%2==1:
sum+=x
print sum

已采纳回答 / 工程电磁场
s和x100赋值没有啊?<...图片...>
Python中,迭代永远是取出元素本身,而非元素的索引。

对于有序集合,元素确实是有索引的。有的时候,我们确实想在 for 循环中拿到索引,怎么办?

方法是使用 enumerate() 函数, 作用是索引化
print r&#039;&#039;&#039;&quot;To be,or not to be&quot;:that is the question.
Whether it&#039;s nobler in the mind to suffer.&#039;&#039;&#039;

最新回答 / 大数据中的男人
在计算机的环境变量path中添加python安装目录即可解决
s = &#039;Python was started in 1989 by \&quot;Guido\&quot;.\t\nPython is free and easy to learn.&#039;
print s
set是无序的
x1 = 1
d = 3
n = 100
xn = x1 + (n-1)*d
s = (x1+xn)*n/2
print xn
print s
L = [1]
n=1
while n&lt;100:
L.insert(n,(n+1)*(n+1))
n=n+1
print sum(L)
def move(n, a, b, c):
if n==1:
print a,&#039;--&gt;&#039;,c
else:
print a,&#039;--&gt;&#039;,b
move(n-1,a,b,c)
print b,&#039;--&gt;&#039;,c
return

move(4, &#039;A&#039;, &#039;B&#039;, &#039;C&#039;)
我认为应该是这样写的
输出:
A --&gt; B
A --&gt; B
A --&gt; B
A --&gt; C
B --&gt; C
B --&gt; C
B --&gt; C
def move(n, a, b, c):
if n==2:
print a,&#039;--&gt;&#039;,b
print a,&#039;--&gt;&#039;,c
print b,&#039;--&gt;&#039;,c
if n&gt;2:
move(n-1, a, c, b)
print a,&#039;--&gt;&#039;,c
move(n-1, b, a, c)
move(4, &#039;A&#039;, &#039;B&#039;, &#039;C&#039;)

看了大家的发现自己的是按照他叙述写的。。。。我写的好麻烦。。。
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作。

微信扫码,参与3人拼团

微信客服

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

帮助反馈 APP下载

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

公众号

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

友情提示:

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消