python中被看作假:FALSE none 0 ‘ ’ " " ( ) [ ] { },其他一切都被解釋為真
0.Python 的 floor 除法現在使用“//”實現,那3.0//2.0您目測會顯示什么內容?
1.0
1.a<b<c 事實上等於?
a<b and b<c
2.不使用IDLE,你可以輕松說出5**-2的值么?
1/25
3.如何簡單判斷一個數是奇數還是偶數?
模2取余,等於0為偶數,等於1為奇數
4.請用最快速度說出答案:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9
4
邏輯運算符的優先次序:not>and>or
動手
1.打印1-100偶數、奇數
num =100
while num:
if num%2==0:
print("偶數為:%s"+%num)
else:
print('奇數為:%s'+%num)
num -=1
附加
print("輸出0~100所有的奇數")
for i in range(100):
if i%2 == 1:
print(i)
2.
i = 1 x = 7 flag = 0 while i < 100: i = i + 1 if (x%2==1)and(x%3==2)and(x%5==4)and(x%6==5): flag = 1 else: x = 7*i if flag ==1: print("階梯數是:",x) else: print("請擴大范圍!")
附小甲魚源代碼:
x = 7 i = 1 flag = 0 while i <= 100: if (x%2 == 1) and (x%3 == 2) and (x%5 == 4) and (x%6==5): flag = 1 else: x = 7 * (i+1) # 根據題意,x一定是7的整數倍,所以每次乘以7 i += 1 if flag == 1: print('階梯數是:', x) else: print('在程序限定的范圍內找不到答案!')