請撰寫一程式,讓使用者輸入兩個正整數a、b(a<=b),輸出從a到b(包含a和b)之間4或9的倍數(一列輸出十個數字、欄寬為4、靠左對齊)以及倍數之個數、總和。
範例輸入1:
5
55
範例輸出1:8 9 12 16 18 20 24 27 28 32
36 40 44 45 48 52 54
17
513
範例輸入2:4
9
範例輸出2:4 8 9
3
21
程式碼:
a = int( input() )
b = int( input() )
total = 0
count = 0
for i in range( a, b + 1 ):
if i % 4 == 0 or i % 9 == 0:
count += 1
print("{:<4d}".format(i), end="")
if count % 10 == 0:
print()
total += i
print()
print( count )
print( total )
沒有留言:
張貼留言