if判断#语法1:
# if 条件:
# code1
# code2
# code3
# ....
# age=180
# height=163
# weight=75
# sex='female'
# is_beautiful=True
#
# if age > 16 and age < 30 and height > 158 and weight < 100 and sex == 'female' and is_beautiful:
# print('表白。。。')
#
# print('=====>other code')
#语法2:
# if 条件:
# code1
# code2
# code3
# ....
# else:
# code1
# code2
# code3
# ....
# age=180
# height=163
# weight=75
# sex='female'
# is_beautiful=True
#
# if age > 16 and age < 30 and height > 158 and weight < 100 and sex == 'female' and is_beautiful:
# print('表白。。。')
# else:
# print('阿姨好')
#语法3:多分枝
# 强调:if的多分枝=但凡有一个条件成立,就不会再往下判断其他条件了
# if 条件1:
# code1
# code2
# code3
# ....
# elif 条件2:
# code1
# code2
# code3
# ....
# elif 条件3:
# code1
# code2
# code3
# ....
# ........
# else:
# code1
# code2
# code3
# ....
# 练习
# 如果:成绩>=90,那么:优秀
#
# 如果成绩>=80且<90,那么:良好
#
# 如果成绩>=70且<80,那么:普通
#
# 其他情况:很差
# score = input('>>: ')
# score=int(score)
# if score >= 90:
# print('优秀')
# elif score >= 80:
# print('良好')
# elif score >= 70:
# print('普通')
# else:
# print('很差')
#语法4:if嵌套
# age=18
# height=163
# weight=75
# sex='female'
# is_beautiful=True
#
# is_successfull=True
#
# if age > 16 and age < 30 and height > 158 and weight < 100 and sex == 'female' and is_beautiful:
# print('表白。。。')
# if is_successfull:
# print('在一起')
# else:
# print('我逗你玩呢')
# else:
# print('阿姨好')
#
#
# print('other code....')
# 如果:今天是Monday,那么:上班
# 如果:今天是Tuesday,那么:上班
# 如果:今天是Wednesday,那么:上班
# 如果:今天是Thursday,那么:上班
# 如果:今天是Friday,那么:上班
# 如果:今天是Saturday,那么:出去浪
# 如果:今天是Sunday,那么:出去浪
# today=input('>>: ')
# if today == 'Monday':
# print('上班')
# elif today == 'Tuesday':
# print('上班')
# elif today == 'Wednesday':
# print('上班')
# elif today == 'Thursday':
# print('上班')
# elif today == 'Friday':
# print('上班')
# elif today == 'Saturday':
# print('出去浪')
# elif today == 'Sunday':
# print('出去浪')
# else:
# print('''必须输入其中一种:
# Monday
# Tuesday
# Wednesday
# Thursday
# Friday
# Saturday
# Sunday
# ''')
today=input('>>: ')
if today == 'Monday' or today == 'Tuesday' or today == 'Wednesday' or today == 'Thursday' or today == 'Friday':
print('上班')
elif today == 'Saturday' or today == 'Sunday':
print('出去浪')
else:
print('''必须输入其中一种:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
''')
while循环
'''
1 什么是循环
循环就是一个重复的过程
2 为何要有循环
人可以重复的去做某一件事
程序中必须有一种机制能够控制计算机像人一样重复地去做某一件事
3 如何用循环
'''
# 语法
# while 条件:
# code1
# code2
# code3
# ...
# user_from_db='egon'
# pwd_from_db='123'
#
# while True:
# inp_user=input('please input your username: ')
# inp_pwd=input('please input your password: ')
# if inp_user == user_from_db and inp_pwd == pwd_from_db:
# print('login successfull')
# else:
# print('user or password err')
#
# while + break: break代表结束本层循环
# user_from_db='egon'
# pwd_from_db='123'
#
# while True:
# inp_user=input('please input your username: ')
# inp_pwd=input('please input your password: ')
# if inp_user == user_from_db and inp_pwd == pwd_from_db:
# print('login successfull')
# break
# else:
# print('user or password err')
# while+continue:continue代表结束本次循环(本次循环continue之后的代码不在运行),直接进入下一次循环
# 强调:continue一定不要作为循环体的最后一步代码
# start=1
#
# while start < 8: #5 < 8
# if start == 4:
# start += 1 #start=5
# continue
# print(start)
# start+=1
# while True:
# print(1)
# print(2)
# print(3)
# user_from_db='egon'
# pwd_from_db='123'
#
# while True:
# inp_user=input('please input your username: ')
# inp_pwd=input('please input your password: ')
# if inp_user == user_from_db and inp_pwd == pwd_from_db:
# print('login successfull')
# break
# else:
# print('user or password err')
# continue
#while循环的嵌套
# user_from_db='egon'
# pwd_from_db='123'
#
# while True:
# inp_user=input('please input your username: ')
# inp_pwd=input('please input your password: ')
# if inp_user == user_from_db and inp_pwd == pwd_from_db:
# print('login successfull')
# while True:
# cmd=input('>>>: ') # cmd='quit'
# if cmd == 'quit':
# break
# print('%s run......' %cmd)
# break
# else:
# print('user or password err')
# user_from_db='egon'
# pwd_from_db='123'
#
# tag=True
# while tag:
# inp_user=input('please input your username: ')
# inp_pwd=input('please input your password: ')
# if inp_user == user_from_db and inp_pwd == pwd_from_db:
# print('login successfull')
# while tag:
# cmd=input('>>>: ') # cmd='quit'
# if cmd == 'quit':
# tag=False
# break
# print('%s run......' %cmd)
# else:
# print('user or password err')
#
# while True:
# 1+1
# while + else
# else的代码会在while循环没有break打断的情况下最后运行
# n=1
# while n < 5:
# if n == 4:
# break
# print(n)
# n+=1
# else:
# print('=====》')
#
# user_from_db='egon'
# pwd_from_db='123'
#
# count=0
# tag=True
# while tag:
# if count == 3:
# print('输错次数过多')
# break
# inp_user=input('please input your username: ')
# inp_pwd=input('please input your password: ')
# if inp_user == user_from_db and inp_pwd == pwd_from_db:
# print('login successfull')
# while tag:
# cmd=input('>>>: ') # cmd='quit'
# if cmd == 'quit':
# tag=False
# break
# print('%s run......' %cmd)
# else:
# print('user or password err')
# count+=1 #count=3 # 输错3次
for循环
# names=['egon','alex_dsb','lxx_sb','yxx_dsb']
# i=0
# while i < len(names): #4 < 4
# print(names[i])
# i+=1
# for循环:可以不依赖索引而取指
# names=['egon','alex_dsb','lxx_sb','yxx_dsb']
# for item in names: #item='lxx_sb'
# print(item)
# dic={'x':1,'y':2,'z':3}
# for k in dic: #k='x'
# print(k,dic[k])
# for vs while
# for可以不依赖于索引取指,是一种通用的循环取指方式
# for的循环次数是由被循环对象包含值的个数决定的,而while的循环次数是由条件决定的
# names=['egon','alex_dsb','lxx_sb','yxx_dsb']
# for i in range(0,len(names)):
# print(names[i])
# for+break
# for+continue
# for+else
# for i in range(10):
# # if i == 4:
# # break
# print(i)
# else:
# print('====>')
#1、有序:但凡有索引的数据都是有序的
#2、可变不可变
#可变类型:在值变了的情况下,id不变,证明在改原值
#不可变类型:在值变了的情况下,id也跟着变,证明不是在改原值