Posts

Python: Finding largest continuous sum in a list/array

 Problem Statement: Given a list of integers (both positive and negative) find the largest continuous sum. e.g.  Input: list1 = [1, 2, -1, 3, 4, 10, 10, -10, -1] Output: 29 Solution: def   largest_cont_sum ( list1 ):     max_sum  =  current_sum  =   0           if   len ( list1 )   ==   0 :          return   " There is no any element in the List "           for  num  in  list1 :         current_sum  =   max ( current_sum  +  num ,  num )         max_sum  =   max ( current_sum ,  max_sum )           return  max_sum list1  =   [ 1 , 2 ,- 1 , 3 , 4 , 10 , 10 ,- 10 ,- 1 ] print ...

Python: Find the missing element

 Problem Statement: Consider array/list of non-negative integers. The second array/list is formed by shuffling the elements of the first array/list and deleting a random element. Given these two arrays/lists, find which element is missing in second array. e.g. list1 = [1, 2, 3, 4, 5, 6] list2 = [2, 5, 4, 6, 3] here missing element is 1. Solution: def   missing_ele ( list1 ,   list2 ):     list1 . sort ()     list2 . sort ()      for  num1 ,  num2  in   zip ( list1 ,  list2 ):          if  num1  !=  num2 :              return  num1      return  list1 [- 1 ] list1  =   [ 1 ,   2 ,   3 ,   4 ,   5 ,   6 ] list2  =   [ 2 ,   4 ,   6 ,   3 ,   5 ] print ( " Missing element is:...

555 Timer as Monostable Multivibrator

Here, I have simulated a Monostable Multivibrator in Proteus design suite.

Python: Addition, Subtraction, Multiplication and Division using function

Program:   #Addition function def addition(a,b):     c=a+b     print("Addition= ",c) print("Enter two numbers") #Subtraction function def subtraction(a,b):     c=a-b     print("Subtraction= ",c) #Multiplication function def multiplication(a,b):     c=a*b     print("Multiplication= ",c) #Division function def division(a,b):     c=a/b     print("Division= ",c) a=float(input()) b=float(input()) addition(a,b) subtraction(a,b) multiplication(a,b) division(a,b) Output: Enter two numbers 8 4 Addition=  12.0 Subtraction=  4.0 Multiplication=  32.0 Division=  2.0

Python: Addition of two numbers using function

Below is a simple addition program demonstrated using function addition. This program shows you how to use function in Python  def addition(a,b): #This is funtion definitation     c=a+b     print("Addition = {}".format(c)) print("Enter two numbers to be added") a=int(input()) b=int(input()) addition(a,b) #call the function addition() by passing two numbers a & b Text in green are comments Output: Enter two numbers to be added 341 12 Addition = 353

Program for addition of two number using Python

 This is a simple program for addition of two numbers using Python. Program takes two numbers as input from the user and prints the sum as output. #Simple Program for addition of two number without using function print("Enter two numbers to be added") #int can have numbers in the range -2147483648 through 2147483647 a=int(input()) #takes first number as input from user b=int(input()) #takes second number as input from user c=a+b           #adds two numbers a & b and saves to c print("Addition of numbers {} and {} is {}".format(a,b,c)) Text in green color shows the comments Output: Enter two numbers to be added 123 123 Addition of numbers 123 and 123 is 246

Upstox Free Demat and Trading account opening

Image
Hi All, Upstox is providing free Demat and Trading account for today. Please do get this benefit as early as possible. Link for Free account opening For Desktop/Laptop users: Click here For Mobile phone users: Click here Upstox benefits: 1. Zero brokerage for first month on all trades. 2. Zero Delivery brokerage for lifetime. Thank you