美文网首页
002_接收用户输入

002_接收用户输入

作者: Nzkalhbxx | 来源:发表于2017-10-14 13:11 被阅读0次
    # 通过用户输入的数据,都是字符串类型的,无论输入的是数字/字符/字符串
    name = input("what is your name: ")
    age = input("how old are you: ")
    print("type of name:", type(name))
    print("type of age:", type(age))
    
    # 字符串的拼接可以使用"+"来实现,且字符串不能拼接数值类型,如需拼接,需要将数值类型转换为字符串类型
    print("my name is "+name+" and i am "+age+" years old")
    liveTime = 99
    print("type of age:", type(age))
    
    # 字符串不能和数值做运算,要进行运算需把字符串类型转换为数值类型
    # print("你还能活:"+(liveTime - age)+"年")
    print("you can stall alive:"+str((liveTime - int(age)))+"年")
    
    运行结果

    相关文章

      网友评论

          本文标题:002_接收用户输入

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