defcompute(): ... n=int(input()) m=int(input()) for i inrange(n): for j inrange(0-i,m-i): print(f'{j:4}',end='') print()
若真正要符合題意,可練習創造二維串列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
defcompute(rows,cols): a=[[0]*cols for _ inrange(rows)] for i inrange(rows): for j inrange(cols): a[i][j]=j-i return a
rows=eval(input()) cols=eval(input())
a=compute(rows, cols) for rows in a: for val in rows: print(f'{val:4}',end='') print()
608 二維串列的索引
把二維看成一維,詳情可看個人頁
1 2 3 4 5 6 7 8 9
lst=[] for _ inrange(9): lst.append(int(input())) mx=max(lst) mn=min(lst) li=lst.index(mx) si=lst.index(mn) print(f'Index of the largest number {mx} is: ({li//3}, {li%3})') print(f'Index of the smallest number {mn} is: ({si//3}, {si%3})')
610
看你喜歡把訊息寫成print 或是寫在input 裡面
1 2 3 4 5 6 7 8 9 10 11
t = [] for i inrange(4): print(f"Week {i+1}:") for j inrange(3): print(f"Day {j+1}:",end="") t.append(eval(input())) avg=sum(t)/len(t) print(f"Average: {avg:.2f}") print(f"Highest: {max(t)}") print(f"Lowest: {min(t)}")