Day: February 23, 2021

Python Example – Write a python program to find heights of the top three building in descending order from eight given buildings

(Python Example for Citizen Data Scientist & Business Analyst)   Write a python program to find heights of the top three building in descending order from eight given buildings. Input: 0 ≤ height of building (integer) ≤ 10,000   Sample Solution: Python Code: print(“Input the heights of eight buildings:”) l = [int(input()) for i in …

Python Example – Write a Python program to reverse the digits of a given number and add it to the original

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to reverse the digits of a given number and add it to the original, If the sum is not a palindrome repeat this procedure.   Sample Solution: Python Code: def rev_number(n): s = 0 while True: k = str(n) if k …

Python Example – Write a Python program to find common divisors between two numbers in a given pair

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find common divisors between two numbers in a given pair.   Sample Solution: Python Code: def ngcd(x, y): i=1 while(i<=x and i<=y): if(x%i==0 and y%i == 0): gcd=i; i+=1 return gcd; def num_comm_div(x, y): n = ngcd(x, y) result = …

Python Example – Write a Python program to find the digits which are absent in a given mobile number

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the digits which are absent in a given mobile number.   Sample Solution: Python Code: def absent_digits(n): all_nums = set([0,1,2,3,4,5,6,7,8,9]) n = set([int(i) for i in n]) n = n.symmetric_difference(all_nums) n = sorted(n) return n print(absent_digits([9,8,3,2,2,0,9,7,6,3])) Sample Output: [1, …

Python Example – Write a Python program to find the number of divisors of a given integer is even or odd

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the number of divisors of a given integer is even or odd.   Sample Solution: Python Code: def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x print(divisor(15)) print(divisor(12)) …

Python Example – Write a Python program that accept a positive number and subtract from this number the sum of its digits

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program that accept a positive number and subtract from this number the sum of its digits and so on. Continues this operation until the number is positive.   Sample Solution: Python Code: def repeat_times(n): s = 0 n_str = str(n) while (n …

Python Example – Write a Python program to find the median among three given numbers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the median among three given numbers.   Sample Solution: Python Code: x = input(“Input the first number”) y = input(“Input the second number”) z = input(“Input the third number”) print(“Median of the above three numbers -“) if y < …

Python Example – Write a Python program to get the third side of right angled triangle from two given sides

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the third side of right angled triangle from two given sides. Note: Use bitwise operations to add two numbers.   Sample Solution: Python Code: def pythagoras(opposite_side,adjacent_side,hypotenuse): if opposite_side == str(“x”): return (“Opposite = ” + str(((hypotenuse**2) – (adjacent_side**2))**0.5)) elif …