Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

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.

Note:

  • For this question, convert the hour_of_dayin string datatype to INT datatype.
  • Sort the output in the ascending order of hour_of_day

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:36



Table:

hour_of_day	 no_of_reactions
     0	          500
     1	          2450
     ..	           ..
     ..	           ..
     23	          400









Given 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.

}


Input

  • The first line of input contains a string brand
  • The second line of input contains a string ram
  • The third line of input contains a number battery
  • The fourth line of input contains a string song
  • The fifth line of input contains a boolean isOnCall

Output

  • The first line of output is a string containing
  • battery before charging, as shown in the sample outputs
  • The second line of output is a string based on
  • battery, as shown in the sample outputs
  • The third line of output is a string containing
  • song, as shown in the sample outputs
  • The fourth line of output is a string "Music stopped"
  • The fifth line of output is a string "No ongoing call to end" or "Call Ended"
  • The sixth line of output is a string "Calling..."
  • The seventh line of output is a string "Call Ended"

Constraints

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

myArray of numbers, write a function to square the alternate numbers of the myArray, starting from index 0 using the array method map.Input

  • The input will be a single line containing an array myArray

Output

  • The output should be a single line containing an array with alternate numbers squared

Constraints

  • Each value in the array must be a number


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().

Input

  • The input will be a single line containing a string myString

Output

  • The output should be a single line containing an array of unique characters


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 ( || ).

Input

  • The first line of input contains a string stringsArray
  • The second line of input contains a string startString
  • The third line of input contains a number endString

Output

  • The output should be a single line containing an array of filtered strings


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

inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.Input

  • The first line of input contains a string inputString
  • The second line of input contains a string subString

Output

  • The output should be a sliced string or inputString (if the inputString does not include the subString)

Sample Input 1

JavaScript

S


Sample Output 1

Script


Sample Input 2

Language

air


Sample Output 2

Language




Using python im trying to create a code that follows these specifications below

A Picologo program consists of zero or more commands ending with the x command. Any input following an x command is ignored. The Picologo commands sre processed in the order in which they appear.

Picologo programs may also contain blank, zero-length lines that should be skipped and do not otherwise affect processing of the Picologo program.

A nonblank line will contain exactly one Picologo command. A picologo command may be one of the following:

- b: moves the turtle backward 1 unit

- d: places the turtle's pen down

- f: moves the turtle forward 1 unit

- l: turns the turtle to the left by 1 degree

- r: turns the turtle to the right by 1 degree

- u: raises the turtle's pen up

- x: exits the Picologo program

Write a Python program that does the following. 

  • Create a string that is a long series of words separated by spaces. The string is your own creative choice. It can be names, favorite foods, animals, anything. Just make it up yourself. Do not copy the string from another source. 
  • Turn the string into a list of words using split
  • Delete three words from the list, but delete each one using a different kind of Python operation. 
LATEST TUTORIALS
APPROVED BY CLIENTS