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

Write a python program to create an array of 10 integers and display the array items. The array should be populated with random integers from 10 to 50. The program should also display separately all the even numbers within the array.


Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.Input


For example, if the given M and N are 4 and 4 respectively. If the matrix elements are

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

If the given K is 3. Rotate each ring of the matrix by 3 elements.

In the above matrix, the elements (1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5) is a ring, similarly, the elements (6, 7, 11, 10) will make a ring.

Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). So the output should be

13 9 5 1

14 7 11 2

15 6 10 3

16 12 8 4


Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order.

For example, if the given sentence is "python is a programming language", the possible unique combination of two are (a, is), (a, language), (a, programming), (a, python), (is, language), (is, programming), (is, python), (language, programming), (language, python), (programming, python). Out of these the combinations, (a, is), (a, programming), (is, python), (language, programming) are not valid as they contain words that are adjacent in the given sentence. So the output should be

a language

a python

is language

is programming

language python

programming python


Set1 and Set2 are the two sets that contain unique integers. Set3 is to be created by taking the union or intersection of Set1 and Set2 using the user defined function Operation(). Perform either union or intersection by reading choice from user. Do not use built in functions union() and intersection() and also the operators “|” and “&“.


Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order.Input


The input will be a single line containing a sentence.Output


The output should be multiple lines, each line containing a valid unique combination of two words. The words in each line should be lexicographical order and the lines as well should be in lexicographical order. A valid combination will not contain the words that appear adjacent in the given sentence. Print "No Combinations" if there are no valid combinations.


Input1:

google.com


Output1:

{'g': 2, 'o': 3, 'l': 1, 'e': 1, 'c' : 1, 'm' : 1}


Input2:

Netflix.com


Output2:

{'N': 1, 'e':1, 't': 1, 'f':1, 'l': 1, 'i': 1, 'x':1, '.': 1, 'c': 1, 'o': 1, 'm':1}





Who discovered python?


write a program that contains two functions i.e., encrypt_string() and decrypt_string()a.encrypt_string(s): Thisfunction uses the following dictionary:encrypt={'a':'1','b':'@','c':'*','d':')','e':'$','f':'#'}This function should accept a string as its parameter and return anencrypted string. To encrypt a string, use the dictionary given above. Read each character of the string(match it with the keyin the dictionary)and replace each character with the given encrypted value(valuein the dictionary)and return the encrypted string.b.decrypt_string(s)This function uses the following dictionary:decrypt={'1':'a','@':'b','*':'c',')':'d','$':'e','#':'f'}This function should accept an encrypted string as its parameter and return the decrypted/original string. To decrypt a string, use the dictionary given above. Read each character of the string(match it with the key in the dictionary) andreplace each character with the given decrypted value(value in the dictionary)and return the decrypted string.


Add two polynomials

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

Output:-

Print the addition of polynomials A and B.

The format for printing polynomials is: Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0,

If co-efficient is zero then don't print the term.

If the term with highest degree is negative, the term should be represented as -Cix^Pi.

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

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

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

Explanation

If M = 4 and polynomial A

For power 0, co-efficient is 5

For power 1, co-efficient is 0

For power 2, co-efficient is 10

For power 3, co-efficient is 6.

If N = 3 and for polynomial B

For power 0, co-efficient is 1

For power 1, co-efficient is 2

For power 2, co-efficient is 4.


How to explain this code?


def readAccounts(accounts,fileName):

  pathlibPath = pathlib.Path(fileName)

  if pathlibPath.exists():

    with open(fileName,'r+') as file:

      accountData = json.load(file)

      for account in accountData:

        accountFromFile=Account()

        accountFromFile.setAccountInformation(account['username'],account['password'],account['name'],account['suname'],account['birthDate'],account['listFriends'])

        accounts.append(accountFromFile)

         

        

     

   

main()


LATEST TUTORIALS
APPROVED BY CLIENTS