Describe the difference between objects and values using the terms “equivalent” and “identical”. Illustrate the difference using your own examples with Python lists and the “is” operator.
Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.
Finally, create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of arguments, parameters, objects, and references.
Create your own unique examples for this assignment. Do not copy them from the textbook or any other source.
Matrix Rotations :-
You are given a square matrix A of dimensions NxN. You need to apply the below given 3 operations on the matrix A.
Rotation: It is represented as R S where S is an integer in {90, 180, 270, 360, 450, ...} which denotes the number of degrees to rotate. You need to rotate the matrix A by angle S in the clockwise direction. The angle of rotation(S) will always be in multiples of 90 degrees.
Update: It is represented as U X Y Z. In initial matrix A (as given in input), you need to update the element at row index X and column index Y with value Z.
After the update, all the previous rotation operations have to be applied to the updated initial matrix.
Querying: It is represented as Q K L. You need to print the value at row index K and column index L of the matrix A. Input
The first line contains a single integer N.
Next N lines contain N space-separated integers Aij (i - index of the row, j - index of the column).
Next lines contain various operations on the array. Each operation on each line (Beginning either with R, U or Q).
-1 will represent the end of input.Output
For each Query operation print the element present at row index K and colum index L of the matrix in its current state.
The below code is successful code for the question, but only one case is running successfully. sample inputs and outputs are given below :
def ReadMatrix():
matrix = []
for i in range(int(input())):
row = [int(j) for j in input().split()]
matrix.append(row)
return matrix
def RotateMatrix(matrix, degrees):
n = len(matrix[0])
rotations = (degrees // 90) % 4
for r in range(rotations):
temp_matrix = []
for i in range(n):
column = [row[i] for row in matrix]
column.reverse()
temp_matrix.append(column)
matrix = temp_matrix
return matrix
matrix = ReadMatrix()
rotation = 0
while True:
line = input().split()
if line[0] == "-1":
break;
elif line[0] == "R":
rotation += int(line[1])
matrix = RotateMatrix(matrix, int(line[1]))
elif line[0] == "U":
matrix[int(line[1])][int(line[2])] = int(line[3])
matrix = RotateMatrix(matrix, rotation)
elif line[0] == "Q":
print(matrix[int(line[1])][int(line[2])])
else:
print("Error: unexpected command '" + line[0] + "'")
exit(1)
Sample Input 1
2
1 2
3 4
R 90
Q 0 0
Q 0 1
R 90
Q 0 0
U 0 0 6
Q 1 1
-1
Sample Output 1
3
1
4
6
Sample Input 2
2
5 6
7 8
R 90
Q 0 1
R 270
Q 1 1
R 180
U 0 0 4
Q 0 0
-1
Sample Output 2
5
8
8
But the sample output generating for the sample input - 2 is :
5
8
5
So, please help me by sending code that I have given above after modified, for getting correct output.
Thankyou.
Get the number of reactions (likes/dislikes) generated in each hour of the day in the year 2020.
Table:
user_id video_id reaction_type reacted_at
2141 1529 LIKE 2012-04-12 04:46
2234 1529 LIKE 2012-04-30 17:47
2245 1529 DISLIKE 2012-05-03 21:24
2570 1529 LIKE 2012-04-14 23:08
2525 1529 LIKE 2012-04-26 23:12
2223 1529 DISLIKE 2012-04-08 12:42
2696 1529 LIKE 2012-04-28 01:53
2192 1529 LIKE 2012-04-21 02:39
2773 1529 LIKE 2012-04-25 16:02
2072 1529 LIKE 2012-04-07 15:00
2215 1529 DISLIKE 2012-04-14 03:12
2033 1529 LIKE 2012-04-16 13:54
2039 1529 DISLIKE 2012-04-25 19:14
2259 1529 LIKE 2012-05-03 14:07
2102 1529 LIKE 2012-04-29 11:44
2254 1529 DISLIKE 2012-04-17 14:15
2446 1529 DISLIKE 2012-04-17 07:03
2861 1529 DISLIKE 2012-04-29 08:38
2930 1529 DISLIKE 2012-04-25 03:46
2022 1529 LIKE 2012-04-25 15:45
2795 1529 LIKE 2012-05-01 22:17
2067 1529 LIKE 2012-04-24 13:27
2783 1529 LIKE 2012-04-23 15:23
2053 1529 DISLIKE 2012-04-13 06:26
2045 1529 DISLIKE 2012-04-20 16:47
2265 1529 LIKE 2012-04-11 12:39
2164 1529 LIKE 2012-04-16 02:58
2190 1529 LIKE 2012-04-11 15:45
2551 1529 LIKE 2012-05-04 04:27
2167 1529 LIKE 2012-05-01 07:55
2925 1529 LIKE 2012-04-11 00:54
2367 1529 LIKE 2012-04-17 17:36Table:
hour_of_day no_of_reactions
0 500
1 2450
.. ..
.. ..
23 400Given code is :-
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
class Mobile {
constructor(brand, ram, battery, isOnCall, song) {
this.brand = brand;
this.ram = ram;
this.battery = battery;
this.isOnCall = isOnCall;
this.song = song;
this.isOnCall = false;
}
onCall() {
this.isOnCall = true;
}
removeCharging() {
console.log("Please remove charging");
}
charging() {
if (this.battery < 100) {
this.battery = 100;
console.log(`Mobile charged ${this.battery}%`);
} else {
console.log(`Mobile is fully charged`);
this.removeCharging();
}
}
playMusic() {
this.song = this.song;
console.log(`Playing ${this.song} song`);
}
stopMusic() {
this.song = this.song;
console.log('Music stopped');
}
makeCall() {
console.log("Calling...");
}
endCall() {
if (this.isOnCall == false) {
this.isOnCall = true;
console.log('No ongoing call to end');
} else if (this.isOnCall == true) {
console.log('Call Ended');
}
}
}
/* Please do not modify anything below this line */
function main() {
const brand = readLine();
const ram = readLine();
const battery = parseInt(readLine());
const song = readLine();
const isOnCall = JSON.parse(readLine());
const myMobile = new Mobile(brand, ram, battery, isOnCall, song);
console.log(`Mobile charged ${myMobile.battery}%`); // The Mobile battery charged percentage
myMobile.charging(); // The Mobile charging
myMobile.playMusic(); // The Mobile will start playing a song
myMobile.stopMusic(); // The Mobile will stop playing a song
myMobile.endCall(); // The Mobile will end a call.
myMobile.makeCall(); // The Mobile will make a call.
myMobile.endCall(); // The Mobile will end a call.
}
0 <=
battery <= 100
sample input :-
Apple
2 GB
90
Waka Waka
false
sample output :-
Mobile charged 90%
Mobile charged 100%
Playing Waka Waka song
Music stopped
No ongoing call to end
Calling...
Call Ended
Sample Input 2 :-
Samsung
8 GB
100
Gangnam Style
true
Sample Output 2 :-
Mobile charged 100%
Mobile is fully charged
Please remove charging
Playing Gangnam Style song
Music stopped
Call Ended
Calling...
Call Ended
please help me for getting the accurate outputs a above, not error is displaying in the output, but the main problem is in the ( Endcall section) I think so.
Once U please run the code you may understand where to modify.
thankyou.
Square at Alternate Indices
Given an array
Sample Input 1
[ 1, 2, 3, 4, 5 ]
Sample Output 1
[ 1, 2, 9, 4, 25 ]
Sample Input 2
[ 2, 4 ]
Sample Output 2
[ 4, 4 ]
and the given code to fill the function is :
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const myArray = JSON.parse(readLine());
/* fill the code in this function */
}
Filter Unique Characters
Given a string
myString as an input, write a JS program to find the unique characters from the myString.
Quick Tip
You can use the array method indexOf().
Sample Input 1
Was it a cat I saw?
Sample Output 1
[
'W', 'a', 's', ' ',
'i', 't', 'c', 'I',
'w', '?'
]
Sample Input 2
I did, did I?
Sample Output 2
[ 'I', ' ', 'd', 'i', ',', '?' ]
String Starts or Ends with given String
Given an array
stringsArray of strings, and startString, endString as inputs, write a JS program to filter the strings in stringsArray starting with startString or ending with endString.
Quick Tip
You can use the array method filter() and logical operator OR ( || ).
Sample Input 1
['teacher', 'friend', 'cricket', 'farmer', 'rose', 'talent', 'trainer']
t
r
Sample Output 1
[ 'teacher', 'farmer', 'talent', 'trainer' ]
Sample Input 2
['dream', 'player', 'read', 'write', 'trend']
p
d
Sample Output 2
[ 'player', 'read', 'trend' ]
String Slicing
Given two strings
Sample Input 1
JavaScript
S
Sample Output 1
Script
Sample Input 2
Language
air
Sample Output 2
Language
Write a Python program that does the following.