1.基本数据类型

1.字符串(引号内):

  name=“我是Manuel”

  name='我是Manuel'

  name="""Manuel"""

  name='''Manuel'''

加法:

  n1="alex"

  n2="conda"

  n3="we"

  n4=n1+n2+n3   #n4="alexcondawe"

乘法:

  n1="alex"

  n2=n1*10    #n2="alexalexalexalexalexalexalexalexalexalex"

2.数字

  age=13

  加减乘除

  a=4**3     #a=4的3次方

  b=39%8  #获取39除以8得到的余数

  c=39//8   #获取39除以8得到的整数结果 4

2.循环

1.死循环:

import time

while 1==1:

  print('ok',time.time())

 

二、while循环

1、基本循环

while 条件:
     
    # 循环体
 
    # 如果条件为真,那么循环体则执行
    # 如果条件为假,那么循环体不执行
#补充:
while 条件:
  代码块
else:
  代码块  
else后代码块只运行一次

2、break

break用于退出所有循环

while True:
    print "123"
    break
    print "456"

3、continue

continue用于退出当前循环,继续下一次循环

while True:
    print "123"
    continue
    print "456"

练习

1、使用while循环输入 1 2 3 4 5 6   8 9 10

2、求1-100的所有数的和

3、输出 1-100 内的所有奇数

4、输出 1-100 内的所有偶数

5、求1-2+3-4+5 ... 99的所有数的和

6、用户登陆(三次机会重试)

#
##1.使用while循环输入1 2 3 4 5 6 8 9 10
#a=1
#while a<=10:
#    if a==7:
#        pass
#    else:
#        print(a)
#    a+=1
#print('done!')    




##2.求1-100的所有数的和
#b=1
#sum_hunderd=0
#while b<=100:
#    sum_hunderd=sum_hunderd+b
#    b+=1
#print(sum_hunderd)



##3.输出1-100内的所有奇数
#c=1
#while c<=100:
#    if c%2==0:
#        pass
#    else:
#        print(c)
#    c+=1


#
##4.输出1-100内的所有偶数
#d=1
#while d<=100:
#    if d%2==0:
#        print(d)
#    else:
#        pass
#    d+=1
#


##5.求1-2+3-4+5...99的所有数的和
#e=1
#sum_e=0
#while e<100:
#    if e%2==0:
#        sum_e=sum_e-e
#    else:
#        sum_e=sum_e+e
#    e+=1
#print(sum_e)    
#    


#6.用户登陆(三次机会重试)
account=input('账户名:')
password=input('密码:')
i=1
while i<=4:
    if i>3:
        print('用户名或密码错误超过3次,账号冻结半小时')
        break
    if account=='admin' and password=='admin':
        print('登陆成功')
        break
    else:
        print('登陆失败,请重试')
        account=input('账户名:')
        password=input('密码:')
    i+=1

 

posted on 2019-02-20 17:04  Manuel  阅读(135)  评论(0编辑  收藏  举报