Day: February 24, 2021

Python Example – Write a Python program to multiplies all the items in a list

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to multiplies all the items in a list.   Sample Solution Python Code: def multiply_list(items): tot = 1 for x in items: tot *= x return tot print(multiply_list([1,2,-8])) Sample Output: -16   Write a Python program to multiplies all the items …

Python Example – Write a Python program to sum all the items in a list

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to sum all the items in a list.   Sample Solution Python Code: def sum_list(items): sum_numbers = 0 for x in items: sum_numbers += x return sum_numbers print(sum_list([1,2,-8])) Sample Output: -5   Write a Python program to sum all the items …

Python Example – Write a Python program to calculate the length of a string

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate the length of a string.   Sample Solution Python Code: def string_length(str1): count = 0 for char in str1: count += 1 return count print(string_length(‘wwwwwwwwwwwwww’)) Sample Output: 14   Write a Python program to calculate the length of a …

Python Example – Given a list of numbers and a number k, write a Python program to check whether the sum of any two numbers from the list is equal to k or not

(Python Example for Citizen Data Scientist & Business Analyst)   Given a list of numbers and a number k, write a Python program to check whether the sum of any two numbers from the list is equal to k or not. For example, given [1, 5, 11, 5] and k = 16, return true since …

Python Example – Write a Python program to compute the sum of first n given prime numbers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to compute the sum of first n given prime numbers. Input: n ( n ≤ 10000). Input 0 to exit the program.   Sample Solution: Python Code: MAX = 105000 print(“Input a number (n≤10000) to compute the sum:(0 to exit)”) is_prime …

Python Example – Write a Python program that accepts numbers as input and sorts them in descending order

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program that accepts six numbers as input and sorts them in descending order. Input: Input consists of six numbers n1, n2, n3, n4, n5, n6 (-100000 ≤ n1, n2, n3, n4, n5, n6 ≤ 100000). The six numbers are separated by a …

Python Example – Write a Python program to compute and print sum of two given integers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to compute and print sum of two given integers (more than or equal to zero). If given integers or the sum have more than 80 digits, print “overflow”. Sample Solution: Python Code: print(“Input first integer:”) x = int(input()) print(“Input second integer:”) …

Python Example – Write a Python program to check whether a point (x,y) is in a triangle or not

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check whether a point (x,y) is in a triangle or not. There is a triangle formed by three points. Input: x1,y1,x2,y2,x3,y3,xp,yp separated by a single space. Sample Solution: Python Code: print(“Input x1,y1,x2,y2,x3,y3,xp,yp:”) x1,y1,x2,y2,x3,y3,xp,yp = map(float, input().split()) c1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1) c2 …

Python Example – Write a program to compute the radius and the central coordinate (x, y) of a circle

(Python Example for Citizen Data Scientist & Business Analyst)   Write a program to compute the radius and the central coordinate (x, y) of a circle which is constructed by three given points on the plane surface. Input: x1, y1, x2, y2, x3, y3 separated by a single space. Sample Solution: Python Code: print(“Input three …