• 练习 更多变量和打印


    格式化方法:
    %c 格式化字符及其ASCII码 %s 格式化字符串 %d 格式化整数 %u 格式化无符号整型 %o 格式化无符号八进制数 %x 格式化无符号十六进制数 %X 格式化无符号十六进制数(大写) %f 格式化浮点数字,可指定小数点后的精度 %e 用科学计数法格式化浮点数 %E 作用同%e,用科学计数法格式化浮点数 %g %f和%e的简写 %G %f 和 %E 的简写 %p 用十六进制数格式化变量的地址
    print("习题5:更多变量和打印!!!")
    
    my_name = 'jiajie.zheng'
    my_age = 27
    my_height = 173 #cm
    my_weight = 120 #G
    my_eyes = 'black'
    my_teeth = 'white'
    my_hair = 'black'
    
    #  %s 表示格式化字符串
    print("Let's talk about %s." %my_name)
    
    # %d 表示格式化数字
    print("He's %d inches tall." %my_height)
    print("He's %d pounds heavy."%my_weight)
    print("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 right
    print("If I add %d,%d,and %d I get %d." %(my_age,my_height,my_weight,my_age + my_height + my_weight))
    
    
    
    print("以下为加分题:1、去掉所有的my_")
    name = 'jiajie.zheng'
    age = 27
    height = 173 #cm
    weight = 120 #G
    eyes = 'black'
    teeth = 'white'
    hair = 'black'
    
    #  %s 表示格式化字符串
    print("Let's talk about %s." %name)
    
    # %d 表示格式化数字
    print("He's %d inches tall." %height)
    print("He's %d pounds heavy."%weight)
    print("Actually that's not too heavy.")
    print("He's got %s eyes and %s hair."%(eyes,hair))
    print("His teeth are usually %s depending on the coffee." %teeth)
    
    #this line is tricky,try to get it exactly right
    print("If I add %d,%d,and %d I get %d." %(age,height,weight,age + height + weight))
    
    print("以下为加分题:2、使用更多的格式化字符,%r:不管什么都打印出来")
    name = 'jiajie.zheng'
    age = 27
    height = 173 #cm
    weight = 120 #G
    eyes = 'black'
    teeth = 'white'
    hair = 'black'
    
    #  %s 表示格式化字符串
    print("Let's talk about %s." %name)
    
    # %d 表示格式化数字
    print("He's %r inches tall." %height)
    print("He's %r pounds heavy."%weight)
    print("Actually that's not too heavy.")
    print("He's got %r eyes and %r hair."%(eyes,hair))
    print("His teeth are usually %r depending on the coffee." %teeth)
    
    #this line is tricky,try to get it exactly right
    print("If I add %r,%r,and %r I get %r." %(age,height,weight,age + height + weight))
    
  • 相关阅读:
    关闭编辑easyui datagrid table
    sql 保留两位小数+四舍五入
    easyui DataGrid 工具类之 util js
    easyui DataGrid 工具类之 后台生成列
    easyui DataGrid 工具类之 WorkbookUtil class
    easyui DataGrid 工具类之 TableUtil class
    easyui DataGrid 工具类之 Utils class
    easyui DataGrid 工具类之 列属性class
    oracle 卸载
    “云时代架构”经典文章阅读感想七
  • 原文地址:https://www.cnblogs.com/aszeno/p/9145862.html
Copyright © 2020-2023  润新知