• 练习 更多变量和打印


    格式化方法:
    %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))
    
  • 相关阅读:
    Socket基础一
    MyBatisPlus【目录】
    MyBatis(十一)扩展:自定义类型处理器
    MyBatis(十一)扩展:批量操作
    MyBatis(十一)扩展:存储过程
    MyBatis(十一)扩展:分页插件PageHelper
    MyBatis(十)插件 4
    09月07日总结
    09月06日总结
    09月03日总结
  • 原文地址:https://www.cnblogs.com/aszeno/p/9145862.html
Copyright © 2020-2023  润新知