Skip to main content

Posts

Showing posts with the label Python

Swapping of variables

There are a couple of classical ways to do it. Let the variables be:- a = 5 b = 10 1. By using temporary variable "temp" (name as per your convenience). temp = a a = b b = temp 2. Without "temp" or any extra variable a = a + b   // 15 b = a - b   // b becomes 5 a = a - b   // a becomes 10 3. In Python like a Boss!! :D a, b = b, a

Solution Python QnA #1

Solution for Python QnA for November 14, 2018. # OUTPUT****************************************** >>> x = input () 12 >>> y = int ( input ( 'Please enter a number' )) Please enter a number45 >>> x + y Traceback (most recent call last): File "<stdin>" , line 1 , in < module > TypeError : must be str , not int >>> y + y 90 >>> x + x '1212' In this (x+y); addition of integer and string is not allowed. hence we get the TypeError.

Python QnA #1

Python QnA for November 14, 2018. >>> x = input () User response : [ 12 ] >>> y = int ( input ( 'Please enter a number' )) User response : Please enter a number[ 45 ] >>> x + y # What would be the output??

behind a Wall… Alright to work from a vpn

Seriously, its been numerous occasions that we run through the issues while downloading packages . Moreover things run seamlessly for many though many could not find the ladder. However the skeleton of ladder is nothing but:- Proxies Repos Firewalls or cleaning the above in various config files (apt.conf, local.conf, etc..) Finally Admins could be a great point of contact. Simple tweaks that hold off the work.. be sure to have these check points..

Simple Queue Implementation using Python

Stacks and Queues are not data structures, they are basically abstract data types. The simple data structure can be an array or a linked list. Queues are FIFO.. First In and First Out. Queues do have real world operations like:- 1.    Token System 2.    Organising data to archive based on age. 3.    Scheduling 4.    Any task which involves first come first serve basis. Below is a simple implementation of Queue using Python. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 class Queue : def __init__ ( self ): self . queue = [] def isEmpty ( self ): return self . queue == [] def enqueue ( self , data): self . queue . append(data) def dequeue ( self ): data = self . queue[ 0 ] del self . queue[ 0 ] return data def peek ( self ): return se...