python学习2
来源:互联网 发布:福建知鱼科技有限公司 编辑:程序博客网 时间:2024/05/01 01:43
1.raw_input函数
name=raw_input("what is your name?")age=raw_input("how old are you?")print name +"is" +age
2.if语句
hasBiscuits=raw_input("do you have a biscuits???")if hasBiscuits=="yes": print "it seems very delicious!"#必须要空四个空格,或者一个tabelse: print"you have trick me!!!"
嵌套式if语句:
hasBiscuits=raw_input("do you have a biscuits???")if hasBiscuits=="yes": print "it seems very delicious!" canHave=raw_input("can you give some for me ?") if canHave=="yes" : print "thank your!!"#注意四个空格问题! else : print "I am angry!"else: print"you have trick me!!!"
elif:elif是else if 的缩写形式,是与if语句并列的语句。
hasBiscuits=raw_input("do you have a biscuits???")if hasBiscuits=="yes": print "it seems very delicious!" canHave=raw_input("can you give some for me ?") if canHave=="yes" : print "thank your!!" else : print "I am angry!"elif hasBiscuits== "no": print"you have trick me!!!"elif hasBiscuits=="donnot know": print "are you foolish?"else: print "hehe......"
3.while循环语句
username=raw_input("what is your name?")message=raw_input("please input your message!")while message!="exit": print username + ":" +message message=raw_input("please input your message!")
注意:
在判断语句中,等于用==,不等于用!=;
while语句还是if语句都不用括号,直接
while a==b :
。。。
。。。
无限循环的while:
while True : print "you are great!!!"
4.if,elif,while综合实验
again="yes"while again == "yes": praiseType=raw_input("select a type you like \n a:personality \n b:appearence \n c:intellengence \n") if praiseType == "a": print "you are human!" elif praiseType == "b": print "you are pretty" elif praiseType == "c": print "you seems clever!" else: print "you are wrong!please choose annother" again = raw_input ("do you want go on? input yes or no!")
5.飞船实验
"""使用if,elif,else和while语句以及函数raw_input()和语句print综合实验。实验的目的是制造一个车,该车辆专属于司机,必须输入正确的密码才能进行下一步的操作!车辆有几个功能,行驶到某个目的地、攻击、自爆。。。"""import timename="CC"password="12345"attemPass=raw_input("please input the password!")while attemPass != password: print "your password is false!\n" attemPass=raw_input("please input the password again:")print "welcome " + name +"!!!!"service="yes"while service == "yes": choose=raw_input("please choose a function:\n a:go to a distination \n b:attack \n c:boom \n") if choose == "a": distination=raw_input("where you want to go???") time.sleep(5) print distination + "is arrived!" elif choose == "b": print "attacking.....\n" time.sleep(2) print "over!!!" elif choose == "c": print "i will boom in 5 minutes....\n" time.sleep(1) print '5...........\n' time.sleep(1) print '4..........\n' time.sleep(1) print '3......\n' time.sleep(3) print 'boom..........\n' else : print "your are wrong!" choose = raw_input("please input again!") service = raw_input("task is over,do you want another service? yes/no")
0 0
- python学习笔记2
- python学习笔记(2)
- Python学习笔记(2)
- python 学习纪录2
- Python学习记录2
- python学习备忘录--2
- python学习---2 (rpyc)
- python学习2
- Python学习笔记【2】
- python学习笔记--2
- python学习笔记2
- Python学习笔记[2]
- python学习笔记--2
- python学习笔记2
- Python 学习笔记 -2
- 学习Python(2)
- python 学习笔记2
- python 学习笔记-2
- ReactNative学习十二-React-Native-Viewpager
- IOS设计模式-单例模式
- Android IntentService完全解析 当Service遇到Handler
- How to delete PACKAGE from HANA studio
- 经过static修饰过变量与不被static修饰的变量在运算中初始值的变化关系
- python学习2
- Windows 环境下Apache HTTP Server 2.2的安装和使用apache转发weblogic集群
- 冒泡排序
- 内容:.content和.scroll-content
- 第五周项目五-长方形类
- criteria
- 《ZooKeeper》 Chapter 2 Getting to Grips with ZooKeeper
- npm安装package.json中的模块依赖
- [Ant][StartWithAnt] 第三章 特性property