编程小白的第一本 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
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 入门书 学习笔记06 第七章 类与可口可乐
- 变成小白的第一本Python入门书,第五章循环与判断课后题答案
- 编程小白的第一本 python 入门书 学习笔记02 第三章 变量与字符串
- 编程小白的第一本 python 入门书 学习笔记05 第六章 数据结构
- 编程小白的第一本 python 入门书 学习笔记07 第八章 开始使用第三方类库
- 编程小白的第一本 python 入门书 学习笔记01 第二章 安装Python环境
- Python(编程小白的第一本 Python 入门书) 学习笔记2——代码练习
- 笔记|《简明Python教程》:编程小白的第一本python入门书
- 笔记|《简明Python教程》:编程小白的第一本python入门书
- linux笔记 第六天 bash编程入门之变量、条件判断、条件测试和for循环等
- python学习笔记(7):条件判断与循环
- Python学习笔记(三)—条件判断与循环
- Python学习笔记_判断和循环
- 廖雪峰python学习笔记6:条件判断、循环
- python流程判断之多层循环学习笔记
- Python学习笔记—条件判断和循环
- Python学习笔记DAY2----判断循环
- python学习笔记2.3- 循环、判断
- python学习笔记(三)条件判断和循环
- Python入门笔记(4)_ 控制流:条件判断和循环语句