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 
a:personality
b:appearence
c:intellengence
"
) 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!
"
attemPass=raw_input("please input the password again:") print "welcome " + name +"!!!!" service="yes" while service == "yes": choose=raw_input("please choose a function:
a:go to a distination
b:attack
c:boom
"
) if choose == "a": distination=raw_input("where you want to go???") time.sleep(5) print distination + "is arrived!" elif choose == "b": print "attacking.....
"
time.sleep(2) print "over!!!" elif choose == "c": print "i will boom in 5 minutes....
"
time.sleep(1) print '5...........
'
time.sleep(1) print '4..........
'
time.sleep(1) print '3......
'
time.sleep(3) print 'boom..........
'
else : print "your are wrong!" choose = raw_input("please input again!") service = raw_input("task is over,do you want another service? yes/no")