Skip to main content

Posts

Showing posts with the label Python

Transfer google play balance to Paytm, PhonePe, Google Pay or any UPI linked bank account.

To transfer google play balance, opinion rewards or gift cards to PayPal, Paytm, PhonePe, Google Pay or any UPI ID linked bank account , you can use QxCredit :Rewards Convertor app which is available on google play store: You will get back 80% of the google play balance. App link:  https://play.google.com/store/apps/details?id=qxcoding.qx_credit_reboot Follow these steps to transfer your play balance to paypal or UPI: 1) download app from play store. 2) login with your google account and phone number. 3) choose a token amount which you want to convert/transfer. 4) Enter your payout details.(UPI ID or PayPal Email) 5) wait for an acknowledgement mail form qxcredit containing information about your purchased token. 6) you will receive the amount within 3 days. 7) if you face any issues you can raise a query on website: https://qx-credit.web.app/#/contact_support About app: Introducing QxCredit : Rewards Converter Convert /Transfer or Exchange your Google Play Balance and opini...

How to clear cache in python

What is Caching? The process of  caching  enables storing of temporary data, the result of which is faster access, load times and speedier experience for the user. Deleting it makes the process to reload assets again. Why to remove cache? It is a good idea to clear your browser cache because it: prevents you from using old forms protects your personal information helps our applications run better on your computer Python code for clearing cache: ''' Clear cache files ''' import os if __name__=='__main__': outer = os.getcwd() cache = os.path.join(outer, 'cache') for f in os.listdir(cache): f = os.path.join(cache, f) os.remove(f) print("Removed {} files.".format(count)) if any doubts or queries please comment 

How to find the height of binary tree ? program (Python)

The height of binary tree is defined as MAX(depth of leaf nodes)  and depth of a node in turn is defined as (n-1) ,where n = the least number of nodes traversed through, to reach that node. For detailed information on Implementing binary tree in python : refer here. Definition of height function: def height(self): if self.root == None: return 0 else: return self._height(self.root, 0) def _height(self, cur_node, cur_height): if cur_node == None: return cur_height left_height = self._height(cur_node.left_child, cur_height + 1) right_height = self._height(cur_node.right_child, cur_height + 1) return max(left_height, right_height) Here, two functions are used one is used to check that if the binary tree exists or not , if exists then it will call the recursive function to traverse the left branch and right branch depth with respect to the root node , and then returns the bigger of the two by comparing. The value of depth(height ) of...

How to create a Binary Tree Program ( Python / C / C++ )

What is a binary tree? A binary tree is categorized as an abstract data type , whose (I/O) ,(R/W) operations are handled by the user defined functions.A binary tree is a special case of a tree DS where each node except leaf nodes has two children's . for creating a binary tree we will define a class / structure node which will contain the members(left child and right child) and the value. class node: def __init__(self, value=None): self.value = value self.left_child = None self.right_child = None Now , we will write the code for inserting elements in our binary tree, we will create the function in another class containing a member which will store the address of root node and add all successive elements under the root node . def insert(self, value): if self.root == None: self.root = node(value) else: self._insert(value, self.root) def _insert(self, value, cur_node): if value ...

Tower of Hanoi C / C++ / Python Program

Tower of hanoi is a mathematical game or puzzle.  It consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a  conical  shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: Only one disk can be moved at a time. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod. No larger disk may be placed on top of a smaller disk. With 3 disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a Tower of Hanoi puzzle is 2 n  − 1, where  n  is the number of disks. For example consider 3 disks ,it can be solved in 2 3  -1 steps : Steps required to be performed for solving tower of hanoi problem  : The uni...

Python and C++ program to implement multiplication of 2d array (Matrix multiplication)

Here, in this program we are going to implement matrix multiplication , suppose matrix 1 has dimensions:m*n and matrix 2 has dimensions :p*q for these two matrix to be multiplied we need to have the number of columns in matrix 1(n) equal to the number of rows in matrix 2(p), if the condition is satisfied then the result of multiplication will be a matrix of order m*q in multiplication the elements of the resultant matrix will be the sum of product of corresponding elements of row(of M1) and column(of M2) //first element in 1st row in given example: res[0][0]+=mat1[0][i] * mat2[i][0] where 0<i<n or p //second element in 1st row: res[0][1]+=mat1[0][i] * mat2[i][1] where 0<i<n or p and so on………… Example : Input : 1 2 3 1 4 5 6 2 7 8 9 3 Output : 14 32 50 Input : 4 3 4 2 4 1 1 1 Output : multiplication not possible n!=p Here goes the main execution part where the calculation is been done: for ( int i = 0 ; i < r1 ; i ++) for ( int...

Python program for integration using simpsons 1/3 - Rule

The above rule is applicable only when n=6k (multiple of 6 ) ,we just have to find the value of y corresponding to (value) of x ,given by y=f(x). Now for implementation of this formula in the program ,we need to first find the value's of y corresponding to each x : for that we have to convert the entered string by the user to a python expression for calculation of required values and then substituting in simpson's formula. The conversion of string to python expression can be achieved by using lambda function: ep=input("Expression ") f = lambda x: eval(ep) here, the input string is first stored in ep   and then converted to python expression (function) using lambda. SOURCE CODE: # SIMPSONS 1/3 -RULE # SOURCE: QXCODING.COM / JATIN YADAV if __name__ == '__main__': ep=input("Expression ") f = lambda x: eval(ep) a, b = map(int, input("limits ").rstrip().split()) n = int(input("number of strips for accuracy ...

How to check if a number is palindrome or not? (Python)

Here i'am going to take two examples one is the basic method (long and general) and other in which i will use some inbuilt function of python to make the program a lot easier. 1st method Here , the idea is to break the digits of a number and place them in their revered order by multiplying 1 with last digit and adding 10*2nd last digit and again adding 100*3rd last digit and so on till we reach to first digit. after getting the reverse of a number we have to check that it is equal to the original number. if __name__ == '__main__': num = int(input()) rem = rev = 0 temp = num while num != 0: rem = num % 10 rev = rev * 10 + rem num //= 10 if temp == rev: print("palindrome") else: print("not palindrome") 2nd method In this method, reversed() built in function will be used to reverse the given number and check if the number is palindrome or not. take input in integer fo...