算数运算符
+ - * / //(整除) %(取余) ** 幂
比三个数那个最大
num1 = input("请输入第一个数字:")
num2 = input("请输入第二个数字:")
num3 = input("请输入第三个数字:")
if num1 > num2 > num3 :
print("最大的值是:",num1,"最小的值是:",num3)
elif num1 >num3 >num2:
print("最大的值是:",num1,"最小的值是:",num2)
elif num2 >num1 >num3:
print("最大的值是:",num2,"最小的值是:",num3)
elif num2 >num3 >num1:
print("最大的值是:",num2,"最小的值是:",num1)
elif num3 > num1 >num2:
print("最大的值是:",num3,"最小的值是:",num2)
elif num3 >num2 > num1:
print("最大的值是:",num3,"最小的值是:",num1)
比较运算符 > < >= <= ==(判断是否等于,一个=是赋值,==才是判断是否相等) !=(不等于) true false
nummax = 0
num1 = int(input("请输入第一个数字:"))
num2 = int(input("请输入第二个数字:"))
num3 = int(input("请输入第三个数字:"))
if num1 > nummax :
nummax = num1
if num2 > nummax :
nummax = num2
if num3 > nummax:
nummax = num3
print("最大的数是:",nummax)
else:
nummax = num2
print("最大的数是:",nummax)
else:
if num3 > nummax:
nummax = num3
print("最大的数是:",nummax)
else:
nummax = num1
print("最大的数是:",nummax)
else:
if num2 > nummax :
nummax = num2
if num3 > nummax:
nummax = num3
print("最大的数是:",nummax)
else:
nummax = num2
print("最大的数是:",nummax)
else :
if num3 > nummax:
nummax = num3
print("最大的数是:",nummax)
else:
nummax = nummax
print("最大的数是:",nummax)
num = 1 #赋值运算符 = += -= /= *= //= %= **=
num += 2 #等价于 num = num +2
num -=2 #等价于 num = num -2
num *=2 #等价于 num = num *2
num /=2 #等价于 num = num /2
num//=2 #等价于 num = num //2
%= #求余
**= #幂
逻辑运算符: not and or 注意逻辑运算符短路原则
and 两个条件都正确,结果才正确
> 5 >3 and 6>3
True
>>> 5> 2 and 6> 7
False
5> 4 and 8> 9
False
or 两个条件有一个正确,结果就正确
not 不
not 5>6
True
优先级加小括号
表达式
1+2
操作数和运算符组合语句或代码