if num1>num2:
max_num= num1
if max_num > num3:
print("Max NUM is",max_num)
else:
print("Max NUM is",num3)
else:
max_num = num2
if max_num > num3:
print("Max NUM is",max_num)
else:
print("Max NUM is",num3)
num += 1 等价于 num = num + 1
num -= 1 等价于 num = 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
and 且,并且
只有两个条件全部为True(正确)的时候, 结果才会为True(正确)
语法:
条件1 and 条件2
5>3 and 6<2 True
or 或,或者
规则:
只要有一个条件为True,则结果为Ture,
5>3 or 6<2
真 或 假not 不,雅蠛蝶not 5>3 == False
not 5<3 == True
a>b and (c>d or (not f))
(not (not True)) or (False and (not True))
条件1 and 条件2
条件1 or 条件2
短路原则:
对于and 如果前面的第一个条件为假,那么这个and前后两个条件组成的表达式 的计算结果就一定为假,第二个条件就不会被计算对于or
如果前面的第一个条件为真,那么这个or前后两个条件组成的表达式 的计算结果就一定为真,第二个条件就不会被计算 True or True and False
猜年龄age = 50user_input_age = int(input("Age is :"))
if ....
while 循环:
while 条件:
print("any")
print("any")
num = 1while num<10: # 2
print(num) # 2
num+=1 # 3
if num == 9: # 3
break
num = 1while num<=100: # num<=100 等价于 True
# while num<=100: 等价于 while True:
if num%2 == 0:
print(num)
num += 1
num = 1while num<=100:
if num%2 == 1:
print(num)
num += 1
age = 50#user_input_age = int(input("Age is :"))flag = Truewhile flag:
user_input_age = int(input("Age is :"))
if user_input_age == age:
print("Yes")
flag =False
elif user_input_age > age:
print("Is bigger")
else:
print("Is smaller")
print("End") break # 终止
age = 50#user_input_age = int(input("Age is :"))#flag = True # break
while True:
user_input_age = int(input("Age is :"))
if user_input_age == age:
print("Yes")
break
elif user_input_age > age:
print("Is bigger")
else:
print("Is smaller")
print("End") continue 继续
if a>b and d<f or 5>3 and d == e:
......
while 条件:
....
else:
...statement 语句
num = 1
while num <= 10:
num += 1
if num == 5:
break
print(num)
else:
print("This is else statement") while 条件1:
.....
while 条件2:
....