2021.8.26打卡
打卡代码
demo8:变量赋值中与C++不同之处
# 博主链接:https://blog.csdn.net/qq_45148277
# email:daozhang123@foxmail.com
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
# 开发时间:2021/8/26 8:59
# ——————解包赋值————————
a, b, c = 1, 2, 3
print(a, b, c)
# ——————Python交换两个变量的值——————
a, b = b, a
print(a, b)
# ——————比较运算符——————
# is, is not 比较的是比较对象的ID地址
list1 = [11, 22, 33]
list2 = [11, 22, 33]
print(list1 == list2)
print(list1 is list2)
print(a is not b)
print(list1 is not list2)
demo9:布尔运算符
# 博主链接:https://blog.csdn.net/qq_45148277
# email:daozhang123@foxmail.com
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
# 开发时间:2021/8/26 9:14
#布尔运算符 and 、or 、not 、in 、not in
# and==&& or==|| not==!
s='hello world'
print('w' in s)
print ('k' not in s)
#——————位运算符——————
print(4&8)
print(4|8)
print(4>>1)
print(4<<1)
demo10:布尔函数
# 博主链接:https://blog.csdn.net/qq_45148277
# email:daozhang123@foxmail.com
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
# 开发时间:2021/8/26 9:44
#测试布尔值
print(bool(False))
print(bool(0))
print(bool(None))
print(bool(""))
print(bool('hell world'))
demo11:if判断语句
# 博主链接:https://blog.csdn.net/qq_45148277
# email:daozhang123@foxmail.com
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
# 开发时间:2021/8/26 14:59
num = int(input('请输入一个整数'))
if num % 2 == 0:
print("该数字为偶数")
else:
print("该数字为奇数")
'''
90-100 A
80-89 B
70-79 C
60-69 D
60以下 E
'''
num2 = int(input('请输入一个整数'))
if 90 <= num2 <= 100:
print("A")
elif 80 <= num2 <= 89:
print("B")
elif 70 <= num2 <= 79:
print("C")
elif 69 <= num2 <= 60:
print("D")
elif num2 < 60:
print("E")
else:
print("成绩有误,数字不在有效范围")
# ——————if嵌套结构——————
answer = input("您是会员吗?y/n")
if answer == 'y':
money = float(input('尊敬的会员,请输入那您付款金额 :'))
money *= 0.8
print("您需要实付金额为:", money)
else:
answer2 = input('充值会员享受八折优惠,是否充值')
if answer2 == 'y':
money = float(input('尊敬的会员,请输入那您付款金额 :'))
money *= 0.8
print("您需要实付金额为:", money)
else:
money = float(input("垃圾平民,请输入付款金额"))
print("您需要实付金额为:", money)
# ——————————if判断简写
a = int(input("输入第一个整数"))
b = int(input("输入第二个整数"))
print("第一个是否大于第二个", "yes" if (a >= b) else "No")
demo12:range函数和pass语句
# 博主链接:https://blog.csdn.net/qq_45148277
# email:daozhang123@foxmail.com
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
# 开发时间:2021/8/26 16:16
# pass语句 不起任何实际作用,仅仅占位让程序不报错
# range()三种创建方式
# 1
r=range(10)
print(r)
print(list(r))
#2
r=range(1,10)
print(list(r))
#3
r=range(1,10,2)
print(list(r))