首页 > 代码库 > python第一步从基础开始(一)

python第一步从基础开始(一)

  1.第一个python程序

print "Hello,World!" #看到它之后我忍不住要给它加上括号跟分号。

 

       2.变量

name = "WenjinLi"
age = 23 #这么不正经的写法,居然都不用区分变量类型

       3.for循环

 

age = 56
for i in range(3):   #想当年在OC里面是这样写的 for(NSString*str in array)呃。。。。
    _age = int(input(‘gessAge:‘))
    if age == _age:
        print(‘Congratulation!‘)
        break
    elif age > _age:
        print(‘think bigger‘)
    else:
        print(‘think smaller!‘)
else:
    print(‘you have tried too manylallala times‘)#刷新三观的认知,居然可以在for循环后加else

for i in range(9):
for j in range(9):
result = (i+1)*(j+1)
print (‘‘‘{0}*{1}={2}‘‘‘.format(i+1,j+1,result))#99乘法表

     4.while循环

count = 0
while count < 3:
    _age = int(input(gessAge:))
    if age == _age:
        print(Congratulation!)
        break
    elif age > _age:
        print(think bigger)
    else:
        print(think smaller!)
    count += 1
else:
    print(you have tried too many times)#while竟然也可以加else

 

  

python第一步从基础开始(一)