九九乘法表:git
for i in range(1, 10):
for j in range(1, i + 1):
print(j, "x", i, "=", i * j, end=" ")
print()app
i = 1
while i < 10:
j = 1
while j <= i:
print(j, "x", i, "=", i * j, end=" ")
j += 1
print()
print("----------------------")
i += 1orm
是否潤年:input
while True:
year = int(input("請輸入一個年份:"))it
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print("{}是閏年".format(year))
else:
print("{}不是閏年".format(year))form
奇偶數判斷:di
while True:
num = input("請輸入一個數:")while
if not num.isdigit():
print("請輸入阿拉伯數字的正整數")
else:
if int(num) % 2 == 0:
print("這個數是偶數")
else:
print("這個數是奇數")數字
阿姆斯特朗數:
numb = input("請輸入一個n位數:") nlen = len(numb) l = [] for i in numb: for j in i: l.append(int(j)**nlen) if sum(l) == int(numb): print("這個數是阿姆斯特朗數!") else: print("這個數不是阿姆斯特朗數!")