polinom = {}
for i in range(2):
n = int(input())
for item in range(n):
p, c = input().split(' ')
p, c = int(p), int(c)
if p in polinom:
polinom[p] += c
else:
polinom[p] = c
res = ''
if len(polinom) == 0:
pass
else:
flag = True
for p in polinom:
if polinom[p] == 0:
continue
if polinom[p] < 0:
if flag:
res += '-'
else:
res += ' - '
else:
if not flag:
res += ' + '
flag = False
if (abs(polinom[p]) == 1) and p == 0:
res += '1'
continue
if abs(polinom[p]) != 1:
res += str(abs(polinom[p]))
if p < 0:
res += 'x^({})'.format(p)
elif p == 1:
res += 'x'
elif p > 0:
res += 'x^{}'.format(p)
if len(res) == 0:
print('0')
else:
print(res)
Output:6 + 2x + 14x^2 + 6x^3
Expected output:6x^3 + 14x^2 + 2x + 6n = int(input())
polinom_a =[0 for item in range(n)] for item in range(n):
p, c = input().split(' ')
polinom_a[int(p)] = int(c)
m = int(input())
polinom_b =[0 for item in range(m)]
for item in range(m):
p, c = input().split(' ')
polinom_b[int(p)] = int(c)
pol_max , pol_min = polinom_a , polinom_b
if len(pol_min) > len(pol_max):
pol_max , pol_min = polinom_b , polinom_a
for item in range(len(pol_min)):
pol_max[item] += pol_min[item]
for item in range(len(pol_max)-1,0,-1):
if item == 0:
continue
print (f'{pol_max[item]}x^{item} + ',end='')
print(pol_max[0])
ouput:6x^3 + 14x^2 + 2x^1 + 6
the ouput should be like this:6x^3 + 14x^2 + 2x + 6
after adding two polynomials when we get "0" as output and it should print output as:"0"so,please can anyone make correct code?
All Possible Subsets
Given a sentence as input, print all the unique combinations of the words of the sentence, considering different possible number of words each time (from one word to N unique words in lexicographical order).Input
The input will be a single line containing a sentence.Output
The output should be multiple lines, each line containing the unique combination from one word to N words in lexicographical order.Explanation
For example, if the given sentence is "apple is a fruit".
All possible one-word unique combinations are
a
apple
fruit
isAll possible two words unique combinations are
a apple
a fruit
a is
apple fruit
apple is
fruit isAll possible three words unique combinations are
a apple fruit
a apple is
a fruit is
apple fruit isAll possible four words unique combinations are
a apple fruit isYou are designing a quiz game to help elementry school students with fraction calculations
Your games should have a set of 25 addition, subtraction, multiplication, division questions located in a file. Each question should be formatted to look like:
The questions should be displayed to the player 1 question at a time and reward the player points for gettting the answer to that question correct.
Your program should always display the correct answer in lowest terms if the player didn't answer in lowest terms correctly
Your program should append the players name and score to a file when complete.
You must design and code a Fraction Object to complete this program
compute average numbers from 1 to n where n is a positiove integer value and assign it to the variable avg in python
inputString =input("");
sumDigits =0
numberDigits=0
# Looping through a string.
for character in inputString:
if (character.isdigit()):
# Calculate the sum of the digits of all numbers that appear in the string
sumDigits+=int(character)
numberDigits+=1
# Calculate the average of the digits of all numbers that appear in the string
average=sumDigits/numberDigits
# Print the sum of all digits(8)
print(str(sumDigits))
# Print the average of all digits(2.0) in the new line.
print("%.1f" % average)
input:
Anjali25 is python4 Expert
ouput:
11
3.7
the output should be like this:
11
3.67M, 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]
for row in output:
print(*row)
input:
2 5
-50 20 3 25 -20
88 17 38 72 -10
output:-
50 -20 -10 3 17
-10 3 17 20 25
the output should be like this:-
50 -20 -10 3 17
20 25 38 72 88so can anyone please give correct code?
Given two polynomials A and B, write a program that adds the given two polynomials A and B.Input
If the add polynomials is euqal to zero it should print output:"0"
MODULE 10:
Go ahead and try to write the code in this module. If you accomplished it and run without an issue, add
another feature of our calculator. Try to add the following:
SAMPLE OUTPUT:
what's the first number?:15
+
-
*
/
%
e
pick an operation:%
what's the number?: 4
15.0% 4.0=3.0
type 'y' to continue calculating with 3.0, or type 'n' to start a new calculation:
SAMPLE OUTPUT:
what's the first number?:5
+
-
*
/
%
e
pick an operation:e
what's the number?: 3
5.0% 3.0= 125.0
type 'y' to continue calculating with 125.0, or type 'n' to start a new calculation:
You are making a 4 player dice game. Each of the four players starts the game by rolling one 5 sided dice and one 8 sided dice. The total is recorded.
Player Object
Attributes:
Constructor:
Behaviours: