Đưa ra một số N, hãy viết một chương trình để in một mẫu hình tam giác của các dòng N với các số như hình dưới đây.
Đầu vào
Đầu vào sẽ là một dòng duy nhất chứa số nguyên dương [N].
Đầu ra
Đầu ra phải là n hàng với số.
Ví dụ: nếu số đã cho là 4 -If the given number is 4 --
1
121
12321
1234321
Nếu số được đưa ra là 7 -
1
121
12321
1234321
123454321
12345654321
1234567654321
Lưu ý: Ở phía bên trái sẽ không có khoảng cách, nó sẽ trông giống như tam giác phải.
Given a number N, write a program to print a triangular pattern of N lines with numbers as shown below.
Input
The input will be a single line containing a positive integer [N].
Output
The output should be N rows with numbers.
Note: There is no space between the numbers.
Explanation
For example, if the given number of rows is 4,
your code should print the following pattern
1
121
12321
1234321
Sample Input 1
4
Sample Output 1
1
121
12321
1234321
Sample Input 2
9
Sample Output 2
1
121
12321
1234321
123454321
1234567654321
123456787654321
12345678987654321
# Reading a value from user
n = int[input[]]
# Looping for n times
for i in range[1,n+1]:
# Looping from 1 to i inclusive
for j in range[1,i+1]:
# Printing value of j
print[j,end=""]
# Looping from i-1 to 1 inclusive
for j in range[i - 1, 0, -1]:
# Printing value of j
print[j, end=""]
# Printing new line
print[]
Ảnh chụp màn hình:
Tìm hiểu thêm về sự giúp đỡ của chúng tôi với các bài tập: Python