100 likes | 130 Views
Find Python Program Which asked in O level Practical by NIELIT . More info https://www.careerbodh.in/blog/categories/python-program
E N D
Python Program Python is a well-liked programming language. It was developed by Guido van Rossum in 1991. It is used for web development (server-side), software development, mathematics, system scripting. Python was designed for readability, and has some similarities to the English language with manipulate from mathematics.
Python program to calculate the factorial of a number • Program: • def fact(n): • if n == 0: • return 1 • else: • return n * fact(n-1) • n=int(input("Enter a number for compute the factorial : ")) • print(fact(n)) • Output: • Enter a number for compute the factorial : 4 • 24
NumPy program to find the most frequent value in the list. • Program: • import numpy as np • x = np.array([1,2,3,4,5,7,2,1,1,1,8,9,1]) • print(x) • print("most frequent value in the list:") • print(np.bincount(x).argmax()) • Output: • [1 2 3 4 5 7 2 1 1 1 8 9 1] • most frequent value in the list: • 1
Python program accept a hyphen-separated sequence of words as input and prints the sorted words • Program: • print("Enter words separated by Hyphens : ") • lst = [n for n in input().split("-")] • lst.sort() • print('-'.join(lst)) • Output: • Enter words separated by Hyphens : • gaurav-ram-yashir-bittu-wong • bittu-gaurav-ram-wong-yashir
Python function that takes two lists and returns True if they have at least one common item. • Program: • def data(lst1, lst2): • result = False • for i in lst1: • for j in lst2: • if i == j: • result = True • return result • print(data([1,2,3,4,5], [5,6,7,8,9,10]))
Python program to compute Fibonacci series using function. • Program: • def fab(x): • if x<2: • return 1 • else: • return fab(x-1)+fab(x-2) • y=int(input("Enter a number :")) • for i in range(y): • print(i, "=", fab(i))
Python program to multiply two numbers by repeated addition • Program: • a = int(input("Enter the first number: ")) • b = int(input("Enter the second number: ")) • product = 0 • for i in range(b): • product= product+a • print(product) • Output: • Enter the first number: 3 • Enter the second number: 4 • 12
Python program to find the power of a number using recursion • Program: • Hello Students this program is very useful for O Level Practical so read it carefully. • def power(x,y): • if y==0: • return 1 • else: • return x * power(x, y-1) • x = float(input("Enter a value of base: ")) • y = int(input("Enter value of exponent: ")) • result = power(x, y) • print(result) • Output: • Enter a value of base: 2 • Enter value of exponent: 3 • 8.0
Python Program to Sort Python Dictionaries by Key or Value • mydict = {'raj': 5, 'raja': 6, • 'sanju': 7, 'mohan': 2, 'surya': 10} • Keys = list(mydict.keys()) • Keys.sort() • sort_dict = {i: mydict[i] for i in Keys} • print(sort_dict)
Python Program to find largest element from the list which provided by user • list = [] • num = int(input("Enter number of elements in list: ")) • for i in range(1, num + 1): • a = int(input("Enter elements: ")) • list.append(a) • print("Largest element is:", max(list)) • Output: • Enter number of elements in list: 3 • Enter elements: 19 • Enter elements: 13 • Enter elements: 88 • Largest element is: 88 • More python Program click below link • https://www.careerbodh.in/blog/categories/python-program