Hits: 10 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to sum of three given integers. However, if two values are equal sum will be zero. Sample Solution Python Code: def sum(x, y, z): if x == y or y == z or x==z: sum = 0 else: …

# Day: February 7, 2021

Hits: 1 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get the least common multiple (LCM) of two positive integers. Sample Solution:- Python Code: def lcm(x, y): if x > y: z = x else: z = y while(True): if((z % x == 0) and (z % …

Hits: 6 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to compute the greatest common divisor (GCD) of two positive integers. Sample Solution Python Code: def gcd(x, y): gcd = 1 if x % y == 0: return y for k in range(int(y / 2), 0, -1): if …

Hits: 4 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program that will accept the base and height of a triangle and compute the area. Python: Area of a triangle A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in …

Hits: 3 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to print out a set containing all the colors from color_list_1 which are not present in color_list_2. Test Data: color_list_1 = set([“White”, “Black”, “Red”]) color_list_2 = set([“Red”, “Green”]) Expected Output : {‘Black’, ‘White’} Sample Solution Python Code: color_list_1 = …

Hits: 26 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to print out all even numbers from a given numbers list in the same order and stop the printing if any numbers that come after 237 in the sequence. Sample numbers list: numbers = [ 386, 462, 47, 418, …

Hits: 0 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to concatenate all elements in a list into a string and return it. Sample Solution Python Code: def concatenate_list_data(list): result= ” for element in list: result += str(element) return result print(concatenate_list_data([1, 5, 12, 2])) Sample Output: 15122 …

Hits: 3 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to create a histogram from a given list of integers. Sample Solution Python Code: def histogram( items ): for n in items: output = ” times = n while( times > 0 ): output += ‘*’ times = …

Hits: 13 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to check whether a specified value is contained in a group of values. Test Data: 3 -> [1, 5, 8, 3] : True -1 -> [1, 5, 8, 3] : False Sample Solution Python Code: def is_group_member(group_data, n): …

Hits: 11 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to test whether a passed letter is a vowel or not. Test whether a passed letter is a vowel or not Sample Solution Python Code: def is_vowel(char): all_vowels = ‘aeiou’ return char in all_vowels print(is_vowel(‘c’)) print(is_vowel(‘e’)) Sample Output: …

Hits: 3 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to find whether a given number (accept from the user) is even or odd, print out an appropriate message to the user. Sample Solution Python Code: num = int(input(“Enter a number: “)) mod = num % 2 if …

Hits: 6 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to count the number 4 in a given list. Sample Solution Python Code: def list_count_4(nums): count = 0 for num in nums: if num == 4: count = count + 1 return count print(list_count_4([1, 4, 6, 7, 4])) …

Hits: 7 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to calculate the sum of three given numbers, if the values are equal then return thrice of their sum. Sample Solution Python Code: def sum_thrice(x, y, z): sum = x + y + z if x == y …

Hits: 10 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to test whether a number is within 100 of 1000 or 2000. Python abs(x) function: The function returns the absolute value of a number. The argument may be an integer or a floating point number. If the argument is …

Hits: 5 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get the the volume of a sphere with radius 6. Python: Volume of a Sphere A sphere is a three-dimensional solid with no face, no edge, no base and no vertex. It is a round body with all …

Hits: 4 (Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to calculate number of days between two dates. Python datetime.date(year, month, day) : The function returns date object with same year, month and day. All arguments are required. Arguments may be integers, in the following ranges: MINYEAR <= year <= MAXYEAR 1 <= month <= 12 1 <= day <= number of days in the given month and year …