by CodeChum Admin
Instructions:
Input
The first line contains a single-letter string.
The second line contains a string.
e
CodeChum is awesome
Output
A line containing a string.
Cody is really awesome
For 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)
Instructions: You should submit your answer to this question as a Python code
with .py extension to the corresponding question in Google Classroom.
Attention: Make sure to write your name, surname, and student ID number.
Question:
(Average speed) Assume a runner runs 14 kilometers in 45 minutes and 30 sec-
onds. Write a program that displays the average speed in miles per hour. (Note that
1 mile is 1.6 kilometers.)
Instructions: You should submit your answer to this question as a Python code
with .py extension to the corresponding question in Google Classroom.
Attention: Make sure to write your name, surname, and student ID number.
Question:
(Physics: find runway length) Given an airplane's acceleration a and take-of
speed v, you can compute the minimum runway length needed for an airplane te
take off using the following formula:
length
2a
Write a program that prompts the user to enter v in meters/second (m/s) and th
acceleration a in meters/second squared (m/s), and displays the minimum runway
length. Here is a sample run:
Enter speed and acceleration: 60, 3.5 Enter
The minimum runway length for this airplane is 514.286 meters
Instructions: You should submit your answer to this question as a Python code
with .py extension to the corresponding question in Google Classroom.
Attention: Make sure to write your name, surname, and student ID number.
Question:
(Physics: find runway length) Given an airplane's acceleration a and take-of
speed v, you can compute the minimum runway length needed for an airplane te
take off using the following formula:
length
2a
Write a program that prompts the user to enter v in meters/second (m/s) and th
acceleration a in meters/second squared (m/s), and displays the minimum runway
length. Here is a sample run:
Enter speed and acceleration: 60, 3.5 Enter
The minimum runway length for this airplane is 514.286 meters
Instructions: You should submit your answer to this question as a Python code
with .py extension to the corresponding question in Google Classroom.
Attention: Make sure to write your name, surname, and student ID number.
Question:
(Geometry: area of a pentagon) Write a program that prompts the user to enter the
length from the center of a pentagon to a vertex and computes the area of the pen-
tagon, as shown in the following figure.
3V3
The formula for computing the area of a pentagon is Area where s is
the length of a side. The side can be computed using the formula s = 2r sin ,
where r is the length from the center of a pentagon to a vertex. Here is a sample
run:
Enter the length from the center to a vertex: 5.5 ter
The area of the pentagon is 108.61
Write a program in python to print respective month of a year.