(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function that takes a sequence of numbers and determines whether all the numbers are different from each other. Sample Solution: Python Code : def test_distinct(data): if len(data) == len(set(data)): return True else: return False; print(test_distinct([1,5,7,9])) print(test_distinct([2,4,5,5,7,9])) Sample Output: True False …
Day: February 20, 2021
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function to find a distinct pair of numbers whose product is odd from a sequence of integer values. Sample Solution Python Code : def odd_product(nums): for i in range(len(nums)): for j in range(len(nums)): if i != j: product = nums[i] * …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function that takes a positive integer and returns the sum of the cube of all the positive integers smaller than the specified number. Ex.: 8 = 73+63+53+43+33+23+13 = 784 Sample Solution Python Code : def sum_of_cubes(n): n -= 1 total = 0 while …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function to find the maximum and minimum numbers from a sequence of numbers. Note: Do not use built-in functions. Sample Solution Python Code : def max_min(data): l = data[0] s = data[0] for num in data: if num> l: l = num …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function to check whether a number is divisible by another number. Accept two integers values form the user. Sample Solution Python Code : def multiple(m, n): return True if m % n == 0 else False print(multiple(20, 5)) print(multiple(7, 2)) Sample …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to find the location of Python module sources. Sample Solution Python Code : import sys print(“\nList of directories in sys module:”) print(sys.path) print(“\nList of directories in os module:”) import os print(os.path) Copy Sample Output: List of directories in sys module: …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to check whether a variable is integer or string. Sample Solution Python Code : print(isinstance(25,int) or isinstance(25,str)) print(isinstance([25],int) or isinstance([25],str)) print(isinstance(“25”,int) or isinstance(“25”,str)) Sample Output: True False True Write a Python program to check whether a variable is integer …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to determine if the python shell is executing in 32bit or 64bit mode on operating system. Sample Solution Python Code: import struct print(struct.calcsize(“P”) * 8) Sample Output: 64 Free Machine Learning & Data Science Coding Tutorials in Python & …
(Python Example for Citizen Data Scientist & Business Analyst) Write a python program to convert decimal to hexadecimal. Sample Solution Python Code: x = 30 print(format(x, ’02x’)) x = 4 print(format(x, ’02x’)) Sample Output: 1e 04 Write a python program to convert decimal to hexadecimal Free Machine Learning & Data Science Coding …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to convert true to 1 and false to 0. Sample Solution Python Code: x = ‘true’ x = int(x == ‘true’) print(x) x = ‘abcd’ x = int(x == ‘true’) print(x) Sample Output: 1 0 Write a Python program …