笨办法05更多的变量和打印

来源:互联网 发布:sql decode函数 编辑:程序博客网 时间:2024/05/29 01:55
my_name = 'Kuro Nico'my_age = 35 - 5                  # Oh, no!heightcm = 7 * 10 + 4my_height = heightcm * 2.54      # inchesmy_weight = 10 % 4 * 90          # lbsmy_eyes = 'Blue'my_teeth = 'White'my_hair = 'Brown'print "Let's talk about %s." % my_nameprint "He's %d inches tall." % my_heightprint "He's %d pounds heavy." % my_weightprint "Actually that's not too heavy."print "He's got %s eyes and %s hair." % (my_eyes, my_hair)print "His teeth are usually %s depending on the coffee." % my_teeth# this line is tricky, try to get it exactly rightprint "If I add %d, %d, and %d I get %d." %(my_age, my_height, my_weight, my_age + my_height + my_weight)

输出结果:
这里写图片描述


以下精度宽度表示方法:

# coding: utf-8from math import piprint 'pi: %.10f' % pi                         # 精度(小数点位数)10print 'pi: %9f' % pi                           # 宽度(字符数)9print '%*.*s' %(20,7, 'May I help you?')       # 使用*作为精度和宽度,数值会从元组参数中读出

输出结果:
这里写图片描述