为了账号安全,请及时绑定邮箱和手机立即绑定
# Enter a code
#coding:utf-8
age=21
if age>=18:
print('adult')
elif age>=6:
print('tennager')
elif age>=3:
print('kid')
else:
print('adult')
# Enter a code
#coding:utf-8
age=19
if age>=18:
print('adult')
else:
print('teenager')
# Enter a code
# coding:utf-8
age=19
if age>=18:
print('adult')
# Enter a code
s='AABCDEFGHHIJ'
a=s[1:9]
print(a)
# coding: utf-8
s1 = '这是中文字符串'
s2 = 'this is an English string'
print(s1+s2)
# Enter a code
# -*- coding: UTF-8 -*-
template='Life is {0},you need {1}'
result=template.format('short','python')
print(result)
print('life is short,you need{}'.format('python'))
print('life is short,you need{launguage}'.format(launguage='python'))
# Enter a code
L = [75, 92, 59, 68, 99]
sum = 0.0
for x in L:
sum = sum + x
print(sum / 5)
# Enter a code
a=21
if a>=18:
print('adult')
elif a>= 6:
print('teenager')
elif a>= 3:
print('kid')
else:
print('baby')
这里,因为score = 59 < 60,所以if的判断是True,因此就会执行print('抱歉,考试不及格')。
这里有几个需要注意的地方:
可以看到print('抱歉,考试不及格')这行代码明显比上一行代码缩进了,这是因为这行代码是if判断的一个子分支,因此需要缩进,在Python规范中,一般使用4个空格作为缩进
在if语句的最后,有一个冒号:,这是条件分支判断的格式,在最后加入冒号:,表示接下来是分支代码块
a=3.14
b=1.57
c=a*b
print(round(c,2))
a='hello world'
b='hello world'
c='hello world'
print(a)
print(b)
print(c)
# Enter a code
a=3.1415926
b='learn python in imooc'
c=100
d=0b1101
print isinstance(a,float)
print isinstance(b,str)
print isinstance(c,int)
print isinstance(d,int)
# coding: utf-8
a='zhe shi zhong guo'
b='这是中国'
c='"这是一句中英文混合的Python字符串:Hello World!"'
print(a)
print(b)
print(c)
# Enter a code
a='Life is short,{}'
b='you need Python.'
result=a.format(b)
print(result)


a='Life is short,{c}'
b='you need Python.'
result=a.format(c=b)
print(result)
# Enter a code
a='Life is short,{}'
b='you need Python.'
result=a.format(b)
print(b)

a='Life is short,{c}'
b='you need Python.'
result=a.format(c=b)
print(result)
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作,灵活使用流程控制语句。

微信扫码,参与3人拼团

微信客服

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

帮助反馈 APP下载

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

公众号

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

友情提示:

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消