002_接收用户输入

2017-10-14  本文已影响0人  Nzkalhbxx
# 通过用户输入的数据,都是字符串类型的,无论输入的是数字/字符/字符串
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)))+"年")
运行结果
上一篇 下一篇

猜你喜欢

热点阅读