(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function to find the Max of three numbers. Sample Solution: Python Code: def max_of_two( x, y ): if x > y: return x return y def max_of_three( x, y, z ): return max_of_two( x, max_of_two( y, z ) ) print(max_of_three(3, 6, …
Day: March 10, 2021
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to construct the following pattern, using a nested loop number. Sample Solution: Python Code: for i in range(10): print(str(i) * i) Sample Output: 1 22 333 4444 55555 666666 7777777 88888888 999999999 Write a Python program to construct …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to create the multiplication table (from 1 to 10) of a number. Sample Solution: Python Code: n = int(input(“Input a number: “)) for i in range(1,11): print(n,’x’,i,’=’,n*i) Sample Output: Input a number: 5 5 x 1 = 5 5 x …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to calculate the sum and average of n integer numbers (input from the user). Input 0 to finish. Sample Solution: Python Code: print(“Input some integers to calculate their sum and average. Input 0 to exit.”) count = 0 sum = …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get next day of a given date. Sample Solution: Python Code: year = int(input(“Input a year: “)) if (year % 400 == 0): leap_year = True elif (year % 100 == 0): leap_year = False elif (year % 4 …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to find the median of three values. Sample Solution: Python Code: a = float(input(“Input first number: “)) b = float(input(“Input second number: “)) c = float(input(“Input third number: “)) if a > b: if a < c: median = a …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to display astrological sign for given date of birth. Sample Solution: Python Code: day = int(input(“Input birthday: “)) month = input(“Input month of birth (e.g. march, july etc): “) if month == ‘december’: astro_sign = ‘Sagittarius’ if (day < 22) …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program that reads two integers representing a month and day and prints the season for that month and day. Sample Solution: Python Code: month = input(“Input the month (e.g. January, February etc.): “) day = int(input(“Input the day: “)) if month …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to check a triangle is equilateral, isosceles or scalene. Note : An equilateral triangle is a triangle in which all three sides are equal. A scalene triangle is a triangle that has three unequal sides. An isosceles triangle is a triangle …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it will return 20. Sample Solution: Python Code: def sum(x, y): sum = x + y if sum in range(15, 20): return 20 else: return …