Title: Python Program For O level Practical
1Python 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.
2Python program to calculate the factorial of a
number
- Program
- def fact(n)
- if n 0
- return 1
- else
- return n fact(n-1)
- nint(input("Enter a number for compute the
factorial ")) - print(fact(n))
- Output
- Enter a number for compute the factorial 4
- 24
3NumPy 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
4Python 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
5Python 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))
6Python program to compute Fibonacci series using
function.
- Program
- def fab(x)
- if xlt2
- return 1
- else
- return fab(x-1)fab(x-2)
- yint(input("Enter a number "))
- for i in range(y)
- print(i, "", fab(i))
7Python 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 producta
- print(product)
- Output
- Enter the first number 3
- Enter the second number 4
- 12
8Python 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 y0
- 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
9Python 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 mydicti for i in Keys
- print(sort_dict)
10Python 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-p
rogram