您的位置:首页 > 编程语言 > Python开发

编程小白的第一本 python 入门书 学习笔记04 第五章 循环与判断

2018-02-10 15:59 886 查看
列表 Listalbum=['BlackStar','DB',25,True]album.append('newsong')print(album[0],album[-1]) bool(0)      #False bool([])     #False bool('')     #False bool(False)  #False bool(None)   #False a_thing= None
 1 < 3and 2 < 5  #True 1 < 3and 2 > 5  #False 1 < 3or 2 > 5   #True 1 > 3or 2 > 5   #False  条件控制ifcondition:do something else:do something  password_list=['*#*#','12345']

def account_login():
    password=input('Password:\n')
   password_correct=password==password_list[-1]
   password_reset=password==password_list[0]

    if password_correct:
        print('Loginsuccess!')
    elif password_reset:
        new_password=input('Entrya new password:\n')
       password_list.append(new_password)
        print("Yourpassword has been changed successfully!")
       account_login()
    else:
        print("Incorrectpassword or invalid input!")
       account_login()

   account_login()   循环 Loopfor循环 for itemin iterable:       do something  songslist = ['HolyDiver', 'Thunderstruck', 'Rebel Rebel']
for song in songslist:
    if song == 'Holy Diver': print(song,' -Dio')
    elif song == 'Thunderstruck': print(song,' -AC/DC')
    elif song == 'Rebel Rebel': print(song,' -David Bowie') 乘法表for i in range(1,10):
    for j in range(1,10):
        print('{0}* {1} = {2}'.format(i,j,i*j), end='\t')
    print('\n')   while循环 whilecondition:do something while1<3:print('1 is less than 3')# Ctrl+C 停止运行  count = 0whileTrue:print('Repeat this line!')count=count+1if count == 5:break
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  笔记 Python