Write a program in python to print respective month of a year.
Instructions:
Instructions
Input
A line containing an integer.
4Output
Multiple lines containing a string.
CodeChum·is·awesome
CodeChum·is·awesome
CodeChum·is·awesome
CodeChum·is·awesomeby CodeChum Admin
Instructions:
Input
A line containing two integers separated by a space.
2 10Output
Multiple lines containing a string and an integer.
Loading...2%
Loading...3%
Loading...5%
Loading...6%
Loading...7%
Loading...9%
Loading...10%by CodeChum Admin
Instructions:
Output
Multiple lines containing an integer.
1
8
64
343
512
.
.
.by CodeChum Admin
Instructions:
Input
A line containing two integers separated by a space.
1 231214238Output
A line containing a string.
Yesby CodeChum Admin
Instructions:
Input
The first line contains a single-letter string.
The second line contains a string.
e
CodeChum is awesomeOutput
A line containing a string.
Cody is really awesomeFor this program, I want an exact output with all test cases passed
M, N = input('Enter M, N: ').split()
M, N = int(M), int(N)
matrix = []
for _ in range(M):
row = [int(x) for x in input().split()]
matrix.append(row)
K = int(input('Enter K: '))
values = matrix[0][:-1] + [x[-1] for x in matrix][:-1] + matrix[-1][::-1][:-1] + [x[0] for x in matrix][::-1][:-1]
values = values[-K:] + values[:-K]
output = matrix
idxs = [(0, j) for j in range(N)][:-1] + [(i, N - 1) for i in range(M)][:-1] + [(M - 1, j) for j in range(N)][::-1][:-1] + [(i, 0) for i in range(M)][::-1][:-1]
idx = 0
for i, j in idxs:
output[i][j] = values[idx]
idx += 1
for i in output:
for j in i:
print(j, end=' ')
print()
Sample Input 1
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Sample Input 2
3 4
1 2 3 4
10 11 12 5
9 8 7 6
2
Sample Output 2
9 10 1 2
8 11 12 3
7 6 5 4
For this program, I want an exact output with all test cases passed and it should not have any brackets.
def rotate1(matrix, n):
a = len(matrix)
n = int(a)
b = int(n/2)
for row in range(0, b):
for col in range(row, (n- row - 1)):
temp = matrix[row][col]
matrix[row][col] = matrix[n - 1 - col][row]
matrix[n - 1 - col][row] = matrix[n - 1 - row][n- 1 - col]
matrix[n - 1 - row][n - 1 - col] = matrix[col][n - 1 - row]
matrix[col][n - 1 - row] = temp
return matrix
matrix = [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12],[13, 14, 15, 16]]
n = len(matrix)
array = rotate1(matrix, n)
for col in array:
print(col, sep=" ")
Sample Input 1
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Sample Input 2
3 4
1 2 3 4
10 11 12 5
9 8 7 6
2
Sample Output 2
9 10 1 2
8 11 12 3
7 6 5 4
Build a GPA calculator that inputs grades of 3 different subjects along with the credit hours
from the user and displays the user’s GPA. The input grades and their corresponding grading
points are given below.Grade Points
A 4.0
A- 3.67
B+ 3.33
B 3.0
B- 2.67
C+ 2.33
C 2.0
C- 1.67
D+ 1.33
D 1.0
F 0
For this program, the output should not have any brackets
M, N = input().split()
M, N = int(M), int(N)
matrix = []
for _ in range(M):
row = [int(x) for x in input().split()]
matrix.append(row)
K = int(input())
values = []
k = 0
l = 0
while (((N - k) > 0) and ((M - l) > 0)) and ((N - k)*(M-l)) > K:
for i in range(k,N):
values.append(matrix[k][i])
for j in range(l+1,M):
values.append(matrix[j][N-1])
for i in range(N-2,k-1,-1):
values.append(matrix[M-1][i])
for j in range(M-2,l,-1):
values.append(matrix[j][k])
values = values[-K:] + values[:-K]
c = 0
for i in range(k,N):
matrix[k][i] = values[c]
c += 1
for j in range(l+1,M):
matrix[j][N-1] = values[c]
c += 1
for i in range(N-2,k-1,-1):
matrix[M-1][i] = values[c]
c += 1
for j in range(M-2,l,-1):
matrix[j][k] = values[c]
c += 1
values = []
k += 1
l += 1
M -= 1
N -= 1
for i in matrix:
print(i)