Day: February 20, 2021

Python Example – Write a Python function that takes a sequence of numbers and determines whether all the numbers are different from each other

Hits: 13 (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 …

Python Example – Write a Python function to find a distinct pair of numbers whose product is odd from a sequence of integer values

Hits: 5 (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 = …

Python Example – Write a Python function that takes a positive integer and returns the sum of the cube

Hits: 20 (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 = …

Python Example – Write a Python function to find the maximum and minimum numbers from a sequence of numbers

Hits: 14 (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 …

Python Example – Write a Python function to check whether a number is divisible by another number

Hits: 5 (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, …

Python Example – Write a Python program to find the location of Python module sources

Hits: 6 (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 …

Python Example – Write a Python program to check whether a variable is integer or string

Hits: 5 (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 …

Python Example – Write a Python program to determine if the python shell is executing in 32bit or 64bit mode on operating system

Hits: 1 (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 Example – Write a python program to convert decimal to hexadecimal

Hits: 5 (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 …