Best python program - PowerPoint PPT Presentation

About This Presentation
Title:

Best python program

Description:

Find most python programs for O-leval, A-0level in careerbodh. – PowerPoint PPT presentation

Number of Views:0
Updated: 3 March 2023
Slides: 11
Provided by: harshtkd
Tags:

less

Transcript and Presenter's Notes

Title: Best python program


1
Python Program
  • This presentation has lots of python program
    which ask in O Level, A Level, BCA, MCA. B.Tech
    etc which are following python program

2
Python 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

3
Python Program to add two numbers
  • num1 int (input(" Please Enter the First
    Number ")) num2 int (input(" Please Enter the
    second number ")) sum num1num2 print('The sum
    of 0 and 1 is 2'.format(num1, num2, sum))
  • Output
  • Please Enter the First Number 3 Please Enter the
    second number 5 The sum of 3 and 5 is 8

4
Python Program to add three numbers
  • a int (input(" Please Enter the First Number
    ")) b int (input(" Please Enter the second
    number "))
  • c int (input(" Please Enter the third number
    ")) sum abc print('The sum of three numbers
    is ",sum)
  • Output
  • Please Enter the First Number 3 Please Enter the
    second number 5
  • Please Enter the third number 2 The sum of three
    numbers is 10

5
There are two method for finding roots of
quadratic equation
  • import cmath
  • a float (input("Enter the value of a ")) b
    float (input("Enter the value of b ")) c
    float (input("Enter the value of c "))
  • dis (b b) - (4 a c)
  • r1(-b cmath.sqrt(dis)) / (2 a) r2(-b -
    cmath.sqrt(dis)) / (2 a)
  • print(" The square roots of given equation are
    0 and 1".format(r1,r2))
  • Output
  • Enter the value of a 1.2
  • Enter the value of b 2.5
  • Enter the value of c 3.5
  • The square roots of given equation are
    (-1.04166666666666671.3533651474093098j) and
    (-1.0416666666666667-1.3533651474093098j)

6
Python Program to Check a Number is a Perfect
Number
  • n int(input("Enter any number ")) sum0 for i
    in range(1, n) if(n i 0) sum sum i if
    (sum n) print("The number is a Perfect
    number!") else print("The number is not a
    Perfect number!")
  • Output
  • Enter any number 6 The number is a Perfect
    number!

7
Python program Swap two Number with temporary
variable
  • aint(input("Enter The First Number "))
  • bint(input("Enter The Second Number "))
  • print("Before SWAPPING a",a," b",b)
  • ca
  • ab
  • bc
  • print("After SWAPPING a ",a," b ",b)
  • Output
  • Enter The First Number 45
  • Enter The Second Number 78
  • Before SWAPPING a 45 b 78
  • After SWAPPING a 78 b 45

8
Python program Swap two Number without temporary
variable
  • a5
  • b15
  • print(a, b)
  • a, bb, a
  • print(a,b)
  • Output
  • 5 15
  • 15 5

9
Python Program to Check number is Palindrome or
Not
  • nint(input("Enter number"))
  • an
  • sum0
  • while(ngt0)
  • rn10
  • sumsum10r
  • nn//10
  • if(asum)
  • print("The number is a palindrome")
  • else
  • print("The number is not a palindrome")
  • Output
  • Enter number121 The number is a palindrome!
  • To Check number is Palindrome or Not Video by
    Rajesh Sir

10
Python Program to Check Armstrong Number
  • n int(input("Enter a number "))
  • sum 0
  • a n
  • while n gt 0
  • digit n 10
  • sum digit 3
  • n // 10
  • if a sum
  • print("Armstrong number")
  • else
  • print("Not Armstrong number")
  • Output
  • Enter a number 153 Armstrong number
Write a Comment
User Comments (0)
About PowerShow.com