Secret Message - 1
Given a string, write a program to mirror the characters of the string in alphabetical order to create a secret message.
Note: Mirroring the characters in alphabetical order replacing the letters 'a' with 'z', 'b' with 'y', ... , 'z' with 'a'. You need to mirror both uppercase and lowercase characters. You can ignore mirroring for all characters that are not letters.
a b c d e f g h i j k l m n o p q r s t u v w x y z
z y x w v u t s r q p o n m l k j i h g f e d c b a
Explanation
Input
For example, if the given input is "python", "p" should replaced with "k", similarly "y" with "b", "t" with "g", "h" with "s", "o" with "l", "n" with "m". So the output should be "kbgslm".
Sample Input 1
python
Sample Output 1
kbgslm
Sample Input 2
Foundations
Sample Output 2
ulfmwzgrlmh
Weekends
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".Input
The first line of input will contain date D1 in the string format.
The second line of input will contain date D2 in the string format.
Output
The output should be a single line containing two integers separated by space
Explanation
For example, if the given dates are "25 Jan 2021" and "14 Feb 2021", the Saturdays and Sundays dates from "25 Jan 2021" to "14 Feb 2021" are
"30 Jan 2021" is a Saturday
"31 Jan 2021" is a Sunday
"6 Feb 2021" is a Saturday
"7 Feb 2021" is a Sunday
"13 Feb 2021" is a Saturday
"14 Feb 2021" is a Sunday
output
Saturday: 3
Sunday: 3
Sample Input 1
25 Jan 2021
14 Feb 2021
Sample Output 1
Saturday: 3
Sunday: 3
Sample Input 2
25 May 2019
22 Dec 2021
Sample Output 2
Saturday: 135
Sunday: 135
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"