python入门第三讲--用户交互

今天写一个用户交互的小程序:

创建一个文件名为play.py的文档:

 

1 death_age=100
2 name=input("your name:")
3 age=input("your age:")  #input接收的所有数据都是字符串,即便输入的是数字,依然会被当成字 符串处理
4 print(type(age))
5 print("your name:",name)
6 print("you can still live for:",death_age-int(age)," years...")

保存后执行:

your name:       #(此时,应输入你的名字如Monchie,然后会输出)
your age:         #(此时,应输入你的年龄如22,然后会输出)
<class 'str'>
your name: Monchie
you can still live for: 78  years...

今天的小程序就写完啦,啾咪啾咪~~

猜你喜欢

转载自www.cnblogs.com/monchie/p/10370506.html
今日推荐