Nov-07-2022, 03:23 PM
(This post was last modified: Nov-08-2022, 11:31 AM by lilliancsk01.)
print('\n'.join(f'{":".join(str(n)[-1]
for l in range(int(l/2+.5)))}{"" if l%2 else ":"}'
for n, l in (lambda n: ((l, n)
for l in range(n)))(int(input("Enter the size of the pattern:")))))
After I run the above code, a syntax error prompt out: unterminated string literal.
How can I fix the syntax error? Please check whether the code is correct.
Write a program that again generates a square, this time of a different pattern. You should again include code that checks the validity of the input value.
The example shows two different executions of the program. Your program code should be similar to the above program. Printing of digits should have wrap-around feature, i.e. after ‘9’ is ‘0’.
Enter the size of the pattern: 5
0:0:0
1:1:1
2:2:2
3:3:3
4:4:4
Enter the size of the pattern: 14
0:0:0:0:0:0:
1:1:1:1:1:1:
2:2:2:2:2:2:
3:3:3:3:3:3:
4:4:4:4:4:4:
5:5:5:5:5:5:
6:6:6:6:6:6:
7:7:7:7:7:7:
8:8:8:8:8:8:
9:9:9:9:9:9:
0:0:0:0:0:0:
1:1:1:1:1:1:
2:2:2:2:2:2:
3:3:3:3:3:3:
for l in range(int(l/2+.5)))}{"" if l%2 else ":"}'
for n, l in (lambda n: ((l, n)
for l in range(n)))(int(input("Enter the size of the pattern:")))))
After I run the above code, a syntax error prompt out: unterminated string literal.
How can I fix the syntax error? Please check whether the code is correct.
Write a program that again generates a square, this time of a different pattern. You should again include code that checks the validity of the input value.
The example shows two different executions of the program. Your program code should be similar to the above program. Printing of digits should have wrap-around feature, i.e. after ‘9’ is ‘0’.
Enter the size of the pattern: 5
0:0:0
1:1:1
2:2:2
3:3:3
4:4:4
Enter the size of the pattern: 14
0:0:0:0:0:0:
1:1:1:1:1:1:
2:2:2:2:2:2:
3:3:3:3:3:3:
4:4:4:4:4:4:
5:5:5:5:5:5:
6:6:6:6:6:6:
7:7:7:7:7:7:
8:8:8:8:8:8:
9:9:9:9:9:9:
0:0:0:0:0:0:
1:1:1:1:1:1:
2:2:2:2:2:2:
3:3:3:3:3:3: