您的位置:首页 > 编程语言 > Python开发

Python廖雪峰教程中的代码·1

2017-04-20 00:00 447 查看
摘要: 廖雪峰的Python教程是非常适合新手的入门教程,以下是我写的一些简单的练习代码。
廖雪峰的官网 http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000
# -*- coding: utf-8 -*-
print("你好")
print('hello world')
print('hello','world') ##','相当于空格
print('1024*768=',1024*768)##计算
#一个简单的交互,交互要在REPL里写
name = input('Please input your name:')
print('你好,',name)
#格式化语言编辑:你好,xx,您本月花费为xx。
'hello,%s'%('world')
'Hi,%s,you have $%d' % ('Lily',10000)
'%3d-%04d'%(303,502)
S1 = 72
S2 = 85
r = (S2-S1)/S1*100
##格式化语句
print('小明的成绩提高了:','%.1f'%r,'%')
##转义符
print(r'Hello,'Xixi'
you should change your password.')
print('Lisa\'\'\'')
print(r'''This's a test.
\n \t \f
so you don't need minding it.''')
##if else语句
s = input('Plz input your birth:')
b = int(s)
if b >=2000:
print('You are a after-00.')
else:
print('You are a before-00.')
####BMI指数计算23333一定要注意数字类型啊类型!
height = float(input('Plz input your height:'))
weight = float(input('Plz input your weight:'))
BMI = weight/(height*height)
if BMI < 18.5:
print('过轻')
elif BMI <25:
print('正常')
elif BMI <28:
print('微胖')
elif BMI <32:
print('肥胖')
else:
print('严重肥胖')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python