n = 12345
a = n % 10 # 個位
b = n // 10 % 10 # 十位
c = n //100 % 10 # 百位
d = n //1000 % 10 # 千位
e = n //10000 # 萬位
print(a, b, c, d, e)
3. 寫出判斷一個數(shù)是否能同時被3和7整除的條件語句
num = 2
# if num % 21 == 0:
if num % 3 == 0 and num % 7 == 0:
print(num, '能同時被3和7整除')
else:
print(num,'不能同時被3和7整除')
4. 寫出判斷一個數(shù)是否能夠被3或者7整除与殃,但是不能同時被3或者7整除
# num % 3 == 0 or num % 7 == 0
# num % 3 == 0 and num % 7 == 0
num = 49
if ((num % 3 == 0 or num % 7 == 0) and (not(num % 3 == 0 and num % 7 == 0))):
print(num, '能夠被3或者7整除,但是不能同時被3或者7整除')
else:
print(num, '不滿足條件')
5. 輸入年,寫代碼判斷輸入的年是否是閏年焕窝,如果是輸出'閏年',否則輸出'不是閏年'
# 能被400整除的年份死陆;
# 能被4整除但同時不能被100整除的年份.
# 滿足上述兩個條件之一的即為閏年.
# year % 400 ==0
# year % 4 == 0 and year % 100 != 0
year = int(input("請輸入年份:"))
if (year % 400 ==0) or (year % 4 == 0 and year % 100 != 0):
print(year, '是閏年')
else:
print(year, '不是閏年')