Questions: 5 831

Answers by our Experts: 5 728

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 & Filtering

Assignment is about a class which describes a jug of water. The jugs have an individual capacity (in litres) and water can be poured in and out. Water in the jug has a temperature which changes as additional water of a given temperature is poured in. For the purpose of this assignment it is assumed that the water's specific heat capacity and its density is temperature-independent. Further, it is assumed that the jug itself has negligible heat capacity and perfect insulation.

The assignment is to define a class Jug which exposes the following methods:

  • Jug creation: This takes a single parameter (aside from the standard self) which is the capacity (maximum volume of water it can accommodate) and creates an empty jug of that capacity.
  • Method pour_out(volume, into_jug=None): Water is poured out of the jug. volume is the volume in litres that is poured out. Alternatively, the string 'all' can be provided as volume, in which case the full volume of water currently in the jug is poured out. If the named parameter into_jug is assigned then the water is poured into the assigned jug. If into_jug isn't assigned, then the water is poured down the drain.
  • Method pour_in(volume, temperature): Water of the given volume and temperature is poured into the jug. Any excess water beyond the jug's capacity goes into the jug, mixes and causes water to overflow.
  • Method temperature(): Returns the temperature of the water in the jug.
  • Method water_volume(): Returns the volume of the water in the jug.
  • Method capacity(): Returns the capacity of the jug.

No other methods or attributes are exposed. Thus, if you define methods or variables to help you implement the class Jug, then their names should start with an underscore.

Assume that the water mixes and achieves a homogeneous temperature without delay. If you pour water into a jug without it overflowing, then the resulting temperature is calculated as expected from the details given at the top.

If the jug is full and added water causes it to overflow, then the temperature of water in the jug is derived as follows. When you pour water of temperature Θ

in

Θin into a full jug with water temperature Θ

Θ, as an infinitesimal volume dV

dV is added Θ

Θ changes to

Θ+dΘ=Θ∗capacity+Θ

in

∗dV

in

capacity+dV

in


.

Θ+dΘ=(Θ∗capacity+Θin∗dVin)/(capacity+dVin).

Integrating this equation will yield the final temperatureΘ(V

in

)

Θ(Vin)after a volumeV

in

Vinwith temperatureΘ

in

Θinhas been poured into a full jug, continuously mixing with the water in the jug and overflowing. Please derive Θ(V

in

)

Θ(Vin) analytically and use the resulting expression in your pour_in() method.


Prefix Suffix

Write a program to check the overlapping of one string's suffix with the prefix of another string.Input


The first line of the input will contain a string A.

The second line of the input will contain a string B.Output


The output should contain overlapping word if present else print "No overlapping".Explanation


For example, if the given two strings, A and B, are "ramisgood" "goodforall"

The output should be "good" as good overlaps as a suffix of the first string and prefix of next.

Sample Input 1

ramisgood

goodforall

Sample Output 1

good

Sample Input 2

finally

restforall

Sample Output 2

No overlapping


Trying:
    overlap('ramisgood', 'goodforall')
Expecting:
    'good'
ok
Trying:
    overlap('final', 'final')
Expecting:
    'final'
ok
Trying:
    overlap('toast', 'tst')
Expecting:
    't'
ok
Trying:
    overlap('', '')
Expecting:
    'No overlapping'
ok
Trying:
    overlap('first', '')
Expecting:
    'No overlapping'
ok
Trying:
    overlap('', 'second')
Expecting:
    'No overlapping'
ok
1 items had no tests:
    __main__
1 items passed all tests:
   6 tests in __main__.overlap
6 tests in 2 items.
6 passed and 0 failed.
Test passed.

Expected:

good

Expected: output 2:

No overlapping

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


For Input:

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


Initial Matrix

1 2

3 4


For R 90, clockwise rotation by 90 degrees, the matrix will become

3 1

4 2


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 3.

For Q 0 1, print the element at row index 0 and column index 1 of A, which is 1.


Again for R 90, clockwise rotation by 90 degrees, the matrix will become

4 3

2 1


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 4.


For U 0 0 6, update the value at row index 0 and column index 1 in the initial matrix to 6. So the updated matrix will be,

6 2

3 4

After updating, we need to rotate the matrix by sum of all rotation angles applied till now(i.e. R 90 and R 90 => 90 + 90 => 180 degrees in clockwise direction).

After rotation the matrix will now become

4 3

2 6


Next for Q 1 1, print the element at row index 1 and column index 1 of A, which is 6.

output

3

1

4

6

11

46



Errors/Warnings:

Traceback (most recent call last):

 File "main.py", line 46, in <module>

  query(matrix, args)

 File "main.py", line 23, in query

  i, j = map(int, _args)

ValueError: too many values to unpack (expected 2)

output:

11

46

23



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


For Input:

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


Initial Matrix

1 2

3 4


For R 90, clockwise rotation by 90 degrees, the matrix will become

3 1

4 2


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 3.

For Q 0 1, print the element at row index 0 and column index 1 of A, which is 1.


Again for R 90, clockwise rotation by 90 degrees, the matrix will become

4 3

2 1


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 4.


For U 0 0 6, update the value at row index 0 and column index 1 in the initial matrix to 6. So the updated matrix will be,

6 2

3 4

After updating, we need to rotate the matrix by sum of all rotation angles applied till now(i.e. R 90 and R 90 => 90 + 90 => 180 degrees in clockwise direction).

After rotation the matrix will now become

4 3

2 6


Next for Q 1 1, print the element at row index 1 and column index 1 of A, which is 6.

output

3

1

4

6

11

46



Errors/Warnings:

Traceback (most recent call last):

 File "main.py", line 46, in <module>

  query(matrix, args)

 File "main.py", line 23, in query

  i, j = map(int, _args)

ValueError: too many values to unpack (expected 2)

output:

11

46

23



Polynomial


Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.


Input


The first line contains a single integer N.

Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.


Output


Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.

If the coefficient is zero, then don't print the term.

If the term with the highest degree is negative, the term should represent -Cix^Pi.

For the term where power is 1, represent it as C1x instead of C1x^1.

If the polynomial degree is zero and the constant term is also zero, then print 0 to represent the polynomial.

For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.


Explanation


If N = 4

For power 0, the coefficient is 5

For power 1, the coefficient is 0

For power 2, the coefficient is 10

For power 3, the coefficient is 6.

Then polynomial represents "6x^3 + 10x^2 + 5"


Constraints


N <= 100

0 <= Pi < 1000

-1000 <= Ci <= 1000



Sample Input

4

0 5

1 0

2 10

3 6


Sample Output

6x^3 + 10x^2 + 5

output 1 success, but

Sample input

5

0 2

1 3

2 1

4 7

3 6

expected:

7x^4 + 6x^3 + x^2 + 3x + 2

I got

6x^3 + 7x^4 + 1x^2 + 3x + 2

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


For Input:

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


Initial Matrix

1 2

3 4


For R 90, clockwise rotation by 90 degrees, the matrix will become

3 1

4 2


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 3.

For Q 0 1, print the element at row index 0 and column index 1 of A, which is 1.


Again for R 90, clockwise rotation by 90 degrees, the matrix will become

4 3

2 1


For Q 0 0, print the element at row index 0 and column index 0 of A, which is 4.


For U 0 0 6, update the value at row index 0 and column index 1 in the initial matrix to 6. So the updated matrix will be,

6 2

3 4

After updating, we need to rotate the matrix by sum of all rotation angles applied till now(i.e. R 90 and R 90 => 90 + 90 => 180 degrees in clockwise direction).

After rotation the matrix will now become

4 3

2 6


Next for Q 1 1, print the element at row index 1 and column index 1 of A, which is 6.

output

3

1

4

6

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 got output:

5

8

5

Output one is success but output 2 is not success



Polynomial

Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.


Input


The first line contains a single integer N.

Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.


Output


Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.

If the coefficient is zero, then don't print the term.

If the term with the highest degree is negative, the term should represent -Cix^Pi.

For the term where power is 1, represent it as C1x instead of C1x^1.

If the polynomial degree is zero and the constant term is also zero, then print 0 to represent the polynomial.

For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.


Explanation


If N = 4

For power 0, the coefficient is 5

For power 1, the coefficient is 0

For power 2, the coefficient is 10

For power 3, the coefficient is 6.

Then polynomial represents "6x^3 + 10x^2 + 5"


Constraints

N <= 100

0 <= Pi < 1000

-1000 <= Ci <= 1000


Sample Input 1

4

0 5

1 0

2 10

3 6


Sample Output 1

6x^3 + 10x^2 + 5


Sample Input 2

5

0 2

1 3

2 1

4 7

3 6


Sample Output 2

7x^4 + 6x^3 + x^2 + 3x + 2


 




i want output like above sample outputs way


Word Count - 2

Given a sentence S, write a program to print the frequency of each word in S, where words are sorted in alphabetical order.


Input


The input will be a single line containing a string S.


Output


The output contains multiple lines, with each line containing a word and frequency of each word in the given string separated by ": ", where words are sorted in alphabetical order.


Explanation


For example, if the given sentence is "Hello world, welcome to python world", the output should be

Hello: 1

python: 1

to: 1

welcome: 1

world: 2



Sample Input 1

Hello world welcome to python world



Sample Output 1

Hello: 1

python: 1

to: 1

welcome: 1

world: 2


Sample Input 2

This is my book


Sample Output 2

This: 1

book: 1

is: 1

my: 1




Prefix Suffix


Write a program to check the overlapping of one string's suffix with the prefix of another string.


Input


The first line of the input will contain a string A.

The second line of the input will contain a string B.


Output


The output should contain overlapping word if present else print "No overlapping".


Explanation


For example, if the given two strings, A and B, are "ramisgood" "goodforall"

The output should be "good" as good overlaps as a suffix of the first string and prefix of next.




for i in range (0, 8, 2): the counter will count by


LATEST TUTORIALS
APPROVED BY CLIENTS