Tag Archives: python example

Python Example – Write a Python program to print all permutations of a given string (including duplicates)

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to print all permutations of a given string (including duplicates).   In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, …

Python Example – Write a Python program to calculate the sum of all digits of the base to the specified power.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate the sum of all digits of the base to the specified power.   Sample Solution: Python Code: def power_base_sum(base, power): return sum([int(i) for i in str(pow(base, power))]) print(power_base_sum(2, 100)) print(power_base_sum(8, 10)) Sample Output: 115 37   Write a Python …

Python Example – Write a Python program to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers.(default value of number=2).   Sample Solution: Python Code: def sum_difference(n=2): sum_of_squares = 0 square_of_sum = 0 for num in …

Python Example – Write a Python program to find the smallest multiple of the first n numbers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the smallest multiple of the first n numbers. Also, display the factors.   Sample Solution: Python Code: def smallest_multiple(n): if (n<=2): return n i = n * 2 factors = [number for number in range(n, 1, -1) if number …

Python Example – Write a Python program to calculate the discriminant value

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate the discriminant value. Note: The discriminant is the name given to the expression that appears under the square root (radical) sign in the quadratic formula.   Sample Solution: Python Code: def discriminant(): x_value = float(input(‘The x value: ‘)) y_value …

Python Example – Write a Python program to calculate surface volume and area of a sphere.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate surface volume and area of a sphere.   Note: A sphere is a perfectly round geometrical object in three-dimensional space that is the surface of a completely round ball. Python: Surface volume and area of a sphere A sphere …

Python Example – Write a Python program to calculate surface volume and area of a cylinder.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate surface volume and area of a cylinder. Note: A cylinder is one of the most basic curvilinear geometric shapes, the surface formed by the points at a fixed distance from a given straight line, the axis of the cylinder. …

Python Example – Write a Python program to calculate the area of a parallelogram.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate the area of a parallelogram. Note: A parallelogram is a quadrilateral with opposite sides parallel (and therefore opposite angles equal). A quadrilateral with equal sides is called a rhombus, and a parallelogram whose angles are all right angles is …