liyihao

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

备注:

#list
classmates = ['Adam', 'Bob', 'Jack']
classmates.insert(1, 'abert')
classmates
#在索引为1的地方增加一个元素
#['Adam', 'abert', 'Bob', 'Jack']

#pop 删除最后的元素,并返回
classmates.pop(3)
#删除索引为3的元素,并返回
#返回'Jack

#tuple 不可更新
#tuple 定义单个元素
tuple1 = (1,)
tuple1

#可变的tuple
t       = ('0', 'a', ['bob', 'abc'])
t[2][0] = 'aaa'
t[2][1] = 'bbb'
t
#('0', 'a', ['aaa', 'bbb'])
#更改的是list


'''
练习
请用索引取出下面list的指定元素:
# -*- coding: utf-8 -*-
L = [
['Apple', 'Google', 'Microsoft'],
['Java', 'Python', 'Ruby', 'PHP'],
['Adam', 'Bart', 'Lisa']
]
----
# 打印Apple:
print(?)
# 打印Python:
print(?)
# 打印Lisa:
print(?)
'''

L = [
['Apple', 'Google', 'Microsoft'],
['Java', 'Python', 'Ruby', 'PHP'],
['Adam', 'Bart', 'Lisa']
]

print (L[0][0])
print (L[1][1])
print (L[2][2])



#if条件判断
#执行特点:从上往下执行,符合条件直接执行,忽略剩下的elif else语句

age = 20
if age >= 6:
    print ('teenager')
elif age < 6:
    print ('child')
else:
    print ('adult')

#上面这段代码执行,就会只执行第一个if,因为已经满足条件了
#就输出了teenager,剩下的都没有执行


#input
#之前我们介绍input,是因为看起来程序好像更灵活一些了
name = input()
print ('hello,',name)
#name 变量被赋值成输入的对象

print (type(name))
#input 返回的是str


'''
练习
小明身高1.75,体重80.5kg。请根据BMI公式(体重除以身高的平方)
帮小明计算他的BMI指数,并根据BMI指数:
 低于18.5:过轻
 18.5-25:正常
 25-28:过重
 28-32:肥胖
 高于32:严重肥胖
用if-elif判断并打印结果:
# -*- coding: utf-8 -*-
height = 1.75
weight = 80.5
----
bmi = ???
if ???:
pass
'''

Height = 1.75
Weight = 80.5

BMI1 = Height * Height
BMI  = Weight / BMI1

#BMI  = Weight / (Height * Height)

if BMI < 18.5:
    print ('lower')
elif BMI >= 18.5 and BMI < 25:
    print ('normail')
elif BMI >= 25 and BMI < 28:
    print ('fat')
else:
    print ('fater')

 

posted on 2017-11-29 09:52  liyihao  阅读(352)  评论(0)    收藏  举报