python学习2

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!"#必须要空四个空格,或者一个tab
else:
    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 time
name="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")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值