0
在這個問題中,我不得不創建一個程序,提示用戶輸入一個數字,然後再次提示要創建多少行。喜歡的東西:For循環方形圖案的數字
1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4 4
這是我想出了,我已經嘗試了許多不同的方法來得到相同的結果,但沒有奏效。
num=int(input("Enter a number between 1 and 10: "))
rows=int(input("Enter how many rows to of numbers: "))
for i in range(num):
print(i,end=" ")
for x in range(rows):
print (x)
這是我想出了輸出:
Enter a number between 1 and 10: 6
Enter how many rows to of numbers: 4
0 1 2 3 4 5 0
1
2
3
但我仍然需要提示用戶 – 3loosh
這是演示代碼。我硬編碼'num'和'rows'。在你的代碼中使用你正在做的'input()'的值。只需替換我的for循環的邏輯。 –
而不是使用範圍(1,num + 1),只需在for循環中使用i + 1即可。 – Jonas