python

简单笔记分享:

#!/usr/bin/env python     #python基本的开头
age = 56     #定义年龄
count = 0    #计数0
while count < 3: #while当计数小于3   
guess_age = raw_input("guess age:")   #自定义变量,编写输出内容里用raw_input  (python版本为2.6.6,python3.0用input)
if int(guess_age) == age:            #if判断,如果变量等于age,int():转换字符串转成整数,str()讲整数值转换成字符串
print "yes, you got it!"              #输出结果
break                                     #break:结束当前循环。continue:跳出本次循环进入下次循环
elif int(guess_age) > age:         #再次判断
print "think smaller..."              #输出
else:                                        #与if....  else...如果...反之....
print "think bigger...."                #输出
count +=1                                #count = count + 1   小于3,加一,继续循环 
if count == 3:                            #if判断,如果计数等于3   
countine_confirm = raw_input("you want to keep guess?")    #countine_confirm:继续确认,raw_input:打印输出结果
if countine_confirm == 'yes':                                     #if判断,继续确认等于yes
count = 0                                                                 #则计数清零,从新循环。如果不是yes。结束全部!

posted @ 2017-05-08 18:18  疯狂的米粒儿  阅读(235)  评论(0编辑  收藏  举报