我是靠谱客的博主 听话大雁,最近开发中收集的这篇文章主要介绍Python学习 day1# 基本运算符#算数运算符# +、-、*、/a = 7b = 2print(a % b) #取模 取余数print(a ** b) #幂# print(a // b) #取整# # 比较运算符# print(a == b)# print(a != b)# print(a > b)# print(a < b)print(a >= b)print(a <= b)#赋值运算x = 1print(x)x = x + 6print(x)x += 6print(x)x -= ,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
# 基本运算符
#算数运算符
# +、-、*、/
a = 7
b = 2
print(a % b) #取模 取余数
print(a ** b) #幂
# print(a // b) #取整
# # 比较运算符
# print(a == b)
# print(a != b)
# print(a > b)
# print(a < b)
print(a >= b)
print(a <= b)
#赋值运算
x = 1
print(x)
x = x + 6
print(x)
x += 6
print(x)
x -= 5
print(x)
x *= 3
print(x)
#逻辑运算 and or not
a = 1
b = 2
c = 3
print(a > b and c > b)
print(a > b or c > b)
#链式赋值
x = 1
y = 1
x = y = 1
#增量赋值
a = 1
a += 1
#交叉赋值
a = 1
b = 2
print(a, b)
a ,b = b ,a
print(a, b)
#变量的解压
a, b, c, d = [1,2,3,4]
print(a, b, c, d)
#流程控制
#if
name_bing = “冰哥”
name_qiang = “强哥”
if name_bing > name_qiang:
print(‘冰仔强’)
else:
print(‘强哥强’)
age = input(“你的年龄:”)
age = int(age)
if age < 18:
print(“你还未成年”)
elif age < 30:
print(“青年”)
elif age < 50:
print(“中年”)
elif age < 100:
print(“老年”)
else:
print(“xxx”)
- 如果 成绩>=90,打印“优秀”
- 如果 成绩>=80,并且 成绩<90,打印“良好”
- 如果 成绩>=70,并且 成绩<80,打印“普通”
- 如果 其他情况:打印“差”
score = input(“请输入你的成绩:”)
score = int(score)
if score >= 90:
print(“优秀”)
elif score >= 80:
print(“良好”)
elif score >= 70:
print(“普通”)
else:
print(“差”)
#while 循环
a = 1
while a < 10:
print(a < 10)
a += 1
print(a)
#break 结束本层循环
#continue 跳出本次循环
a = 1
while True:
a += 1
if a == 10:
print(“冰哥DSB”)
continue
elif a == 20:
print(“文中XSB”)
break
print(“啊啊啊”)
#输入三次机会,错误则锁定
#登录成功之后可以执行指令,输入exit之后退出
count = 1
tag = True
while tag:
uname = “aj”
pwd = 123
name = input(“请输入用户名:”)
password = int(input(“请输入密码:”))
if name == uname and password == pwd:
print(“登录成功!!!”)
while True:
cmd = input(“请输入你的指令:”)
print(f"执行{cmd}指令")
if cmd == ‘exit’:
tag=False
else:
if count == 3:
print(“三次输入错误,账户锁定!!!”)
break
print(“账户密码错误!”)
count += 1
最后
以上就是听话大雁为你收集整理的Python学习 day1# 基本运算符#算数运算符# +、-、*、/a = 7b = 2print(a % b) #取模 取余数print(a ** b) #幂# print(a // b) #取整# # 比较运算符# print(a == b)# print(a != b)# print(a > b)# print(a < b)print(a >= b)print(a <= b)#赋值运算x = 1print(x)x = x + 6print(x)x += 6print(x)x -= 的全部内容,希望文章能够帮你解决Python学习 day1# 基本运算符#算数运算符# +、-、*、/a = 7b = 2print(a % b) #取模 取余数print(a ** b) #幂# print(a // b) #取整# # 比较运算符# print(a == b)# print(a != b)# print(a > b)# print(a < b)print(a >= b)print(a <= b)#赋值运算x = 1print(x)x = x + 6print(x)x += 6print(x)x -= 所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复