Python Answers

Questions answered by Experts: 5 288

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

Problem Statement.

Design a ‘book’ class with title, author, publisher, price and author’s royalty as instance

variables. Provide getter and setter properties for all variables. Also define a method

royalty() to calculate royalty amount author can expect to receive the following royalties:10%

of the retail price on the first 500 copies; 12.5% for the next 1,000 copies sold, then 15% for

all further copies sold.

Then design a new ‘ebook’ class inherited from ‘book’ class. Add ebook format (EPUB, PDF,

MOBI etc) as additional instance variable in inherited class.

Override royalty() method to deduct GST @12% on ebooks


Problem Statement

Design a ‘book’ class with title, author, publisher, price and author’s royalty as instance

variables. Provide getter and setter properties for all variables. Also define a method

royalty() to calculate royalty amount author can expect to receive the following royalties:10%

of the retail price on the first 500 copies; 12.5% for the next 1,000 copies sold, then 15% for

all further copies sold.

Then design a new ‘ebook’ class inherited from ‘book’ class. Add ebook format (EPUB, PDF,

MOBI etc) as additional instance variable in inherited class.

Override royalty() method to deduct GST @12% on ebooks


M, N = input().split(' ')

M, N = int(M), int(N)

matrix = []

for i in range(M):

row = [int(j) for j in input().split(' ')]

matrix.append(row)

values = [j for row in matrix for j in row]

values.sort()

output = matrix

for i in range(M):

for j in range(N):

output[i][j] = values[i * M + j]

print(output)

input:

3 3

1 20 3

30 10 2

5 11 15

output:[[1, 2, 3], [5, 10, 11], [15, 20, 30]]

the output should be like this:

1 2 3 
5 10 11 
15 20 30 

so, can anyone please give the correct code?


Given two polynomials A and B, write a program that adds the given two polynomials A and B.\

input:

4

0 5

1 0

2 10

3 6

3

0 1

1 2

2 4

output:

6x^3 + 14x^2 + 2x + 6





Please provide the code below. And also give the procedure in a table form.


Using the discussed methods, Convert the following Infix Expression to its equivalent Postfix and Prefix Expression


1. a^b/c+d-(e/f-g+(h+i-j)^k+l-m/n)

2. a/b^c^d+(e+f)/g^h-i*j/(k*l*'m^n)


Stacks and Queues

Please provide the code. Thank you! And also provide the given steps in a table form


A. Create a program that will separate the operators from the operand entered by the user. Use stacks and operators will be limited with +,-, /, and *.


Sample Input: 1+2/3 * 4+5



Number to English Words

Write a program to convert a non-negative integer

N to its English words representation.Input

The input will be a single line containing an integer

N. Note: The input number will not be greater than 1010.OutputN. Note: Don't use any libraries function tools


The output should be a single line containing the representation of the English words of number

N. See the sample input and output for the English words of numbers in places.Explanation

For example, if the given number is 123, your code should print the English words representation, which is

One Hundred Twenty Three

Sample Input 1

123

Sample Output 1

One Hundred Twenty Three

Sample Input 2

10005

Sample Output 2

Ten Thousand Five

Sample Input 3

1234567891

Sample Output 3

One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One






Given a list of integers, write a program to print the count of all possible unique combinations of numbers whose sum is equal to K.

The output should be containing the count of all unique combinations of numbers whose sum is equal to K.

Sample Input 1

2 4 6 1 3

6

Sample Output 1

3


CODE:

---------

from itertools import combinations


# Get a list of numbers from input

numbers = [int(n) for n in input().split()]

# Get K value from input

k = int(input())

# Count combinations that sum to K

count = 0

# Try combinations of all possible sizes

for i in range(1, len(numbers)+1):

  # Try all combinations of size i

  for c in combinations(numbers, i):

    # If this combination sums to K, then increase the count

    if sum(c) == k:

      count += 1

# Output the count

print(count)


In the above code, using import tools like combinations.


Can you please help me to write the code without using import tools?


Write a program that reads all the match outcomes and summarizes the information of all the matches.

Points are given to the teams based on the outcome of the match.

A win earns a team 3 points. A draw earns 1. A loss earns 0.

The following information is expected:

MP: Matches Played

W: Matches Won

D: Matches Drawn (Tied)

L: Matches Lost

P: Points


The team information should be displayed in descending order of points.

sample Input:

6

CSK;RR;loss

RR;DD;draw

MI;KKR;win

KKR;RR;loss

CSK;DD;draw

MI;DD;draw


output:

Team: RR, Matches Played: 3, Won: 2, Lost: 0, Draw: 1, Points: 7
Team: MI, Matches Played: 2, Won: 1, Lost: 0, Draw: 1, Points: 4
Team: DD, Matches Played: 3, Won: 0, Lost: 0, Draw: 3, Points: 3
Team: CSK, Matches Played: 2, Won: 0, Lost: 1, Draw: 1, Points: 1
Team: KKR, Matches Played: 2, Won: 0, Lost: 2, Draw: 0, Points: 0

Given two dates D1 and D2, write a program to count the number of Saturdays and Sundays from D1 to D2 (including D1 and D2).

The date in string format is like "8 Feb 2021".

sample input:

25 Jan 2021

14 Feb 2021

output:

Saturday: 3

Sunday: 3



LATEST TUTORIALS
APPROVED BY CLIENTS