美文网首页
笨方法学python-练习11-提问

笨方法学python-练习11-提问

作者: Demoary | 来源:发表于2017-02-12 15:50 被阅读0次

    练习11-提问

    • 练习程序
    • 课后练习

    练习程序

    # -*- coding: utf-8 -*-
    #raw_input(),原始字符%r格式输出
    print "How old are you?",
    age = raw_input()
    print "How tall are you?",
    height = raw_input()
    print "How much do you weigh?",
    weight = raw_input()
    print "So, you're %r old, %r tall and %r heavy." % (
        age, height, weight)
    #raw_input(),字符串格式%s输出
    print "你多大啦?",
    age = raw_input()
    print "你多高",
    height = raw_input()
    print "你多重",
    weight = raw_input()
    print "So,你有%s岁了,你身高有%s,你体重有%s"%(age,height,weight)
    #in_put()
    print "你多大啦?",
    age = input()
    print "你多高",
    height = input()
    print "你多重",
    weight = input()
    print "So,你有%r岁了,你身高有%r,你体重有%r"%(age,height,weight)
    

    运行结果

    RESTART: F:\python大师\习题\ex11.py 
    How old are you? 29
    How tall are you? 178cm
    How much do you weigh? 65kg
    So, you're '29' old, '178cm' tall and '65kg' heavy.
    你多大啦? 29岁
    你多高 1米78
    你多重 130斤
    So,你有29岁岁了,你身高有1米78,你体重有130斤
    你多大啦? 29
    你多高 "1米78"
    你多重 "65公斤"
    So,你有29岁了,你身高有'1\xc3\xd778',你体重有'65\xb9\xab\xbd\xef'
    

    课后练习

    What's the difference between input() and raw_input()?
    The input() function will try to convert things you enter as if they were Python code, but it has security problems so you should avoid it.
    

    其他课后练习及问题就不看了,主要网上找资料对比了一下input和raw_input的区别,前者说白了接收到的内容直接按照python格式处理了,比如接收一个数字其实就是int或者float类型的,而如果接收一个字符串必须加字符串标志引号,后者对于输入的内容都会处理成字符串,哪怕只是输入一个数字,其实也是被当成一个字符串在处理的,我的本节课程序也用此处扩展了一些,也能从中看出来

    相关文章

      网友评论

          本文标题:笨方法学python-练习11-提问

          本文链接:https://www.haomeiwen.com/subject/neuaittx.html