(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])) print(list_count_4([1, …
(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 == …
(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 a …
(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 points …
(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 …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to print the calendar of a given month and year. Note: Use ‘calendar’ module. Python calendar.month(theyear, themonth, w=0, l=0): The function returns a month’s calendar in a multi-line string using the formatmonth() of the TextCalendar class. ‘l’ specifies the number …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to display the first and last colors from the following list. color_list = [“Red”,”Green”,”White” ,”Black”] Sample Solution:- Python Code: color_list = [“Red”,”Green”,”White” ,”Black”] print( “%s %s”%(color_list[0],color_list[-1])) Sample Output: Red Black Display the first and last colors from a given …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers. Sample data: 3, 5, 7, 23 Python list: A list is a container which holds comma separated values (items or elements) between square brackets …
(Python Example for Citizen Data Scientist & Business Analyst) Exercise: Write a Python program which accepts the radius of a circle from the user and compute the area. Python: Area of a Circle In geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a …
(Python Tutorials for Citizen Data Scientist) Python Program to Illustrate Different Set Operations In this example, we have defined two set variables and we have performed different set operations: union, intersection, difference and symmetric difference. Python offers a datatype called set whose elements must be unique. It can be used to perform different set operations …