Day: March 16, 2021

Python Example – Write a Python program to add, subtract, multiply and division of two complex numbers.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to add, subtract, multiply and division of two complex numbers.   Sample Solution: Python Code: print(“Addition of two complex numbers : “,(4+3j)+(3-7j)) print(“Subtraction of two complex numbers : “,(4+3j)-(3-7j)) print(“Multiplication of two complex numbers : “,(4+3j)*(3-7j)) print(“Division of two complex numbers …

Python Example – Write a Python program to print a complex number and its real and imaginary parts.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to print a complex number and its real and imaginary parts.   Sample Solution: Python Code: cn = complex(2,3) print(“Complex Number: “,cn) print(“Complex Number – Real part: “,cn.real) print(“Complex Number – Imaginary part: “,cn.imag) Sample Output: Complex Number: (2+3j) Complex Number …

Python Example – Write a Python program to convert a binary number to decimal number.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to convert a binary number to decimal number.   Sample Solution: Python Code: b_num = list(input(“Input a binary number: “)) value = 0 for i in range(len(b_num)): digit = b_num.pop() if digit == ‘1’: value = value + pow(2, i) print(“The …

Python Example – Write a Python program to find the roots of a quadratic function.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the roots of a quadratic function.   Sample Solution: Python Code: from math import sqrt print(“Quadratic function : (a * x^2) + b*x + c”) a = float(input(“a: “)) b = float(input(“b: “)) c = float(input(“c: “)) r = …

Python Example – Write a Python program to calculate wind chill index.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate wind chill index.   Sample Solution: Python Code: import math v = float(input(“Input wind speed in kilometers/hour: “)) t = float(input(“Input air temperature in degrees Celsius: “)) wci = 13.12 + 0.6215*t – 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16) print(“The …

Python Example – Write a python program to calculate the area of a regular polygon.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a python program to calculate the area of a regular polygon.   Sample Solution: Python Code: from math import tan, pi n_sides = int(input(“Input number of sides: “)) s_length = float(input(“Input the length of a side: “)) p_area = n_sides * (s_length ** 2) …

Python Example – Write a Python program to calculate distance between two points using latitude and longitude.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate distance between two points using latitude and longitude.   Sample Solution: Python Code: from math import radians, sin, cos, acos print(“Input coordinates of two points:”) slat = radians(float(input(“Starting latitude: “))) slon = radians(float(input(“Ending longitude: “))) elat = radians(float(input(“Starting latitude: …

Python Example – Write a python program to find the next smallest palindrome of a specified number.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a python program to find the next smallest palindrome of a specified number. A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 15951, for example, it is “symmetrical”. The term palindromic is derived from …

Python Example – Write a Python program to print all primes (Sieve of Eratosthenes) smaller than or equal to a specified number.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to print all primes (Sieve of Eratosthenes) smaller than or equal to a specified number. In mathematics, the sieve of Eratosthenes, one of a number of prime number sieves, is a simple, ancient algorithm for finding all prime numbers up to …