Skip to main content
 IMPORTANT PYTHON PROGRAMS FOR CLASS 11th

1. 
""" Program to Calculate Simple Interest """ 

p = eval(input("Enter Principle? "))
r = eval(input("Enter Rate? "))
t = eval(input("Enter Time? "))
si = p *r * t/100
print("Simple interest = ", si) 

2. 
"""  Program to Calculate Compound Interest """ 

p = eval(input("Enter Principle? "))
r = eval(input("Enter Rate? "))
t = eval(input("Enter Time? "))
A = p * (1 + r/100) ** t
CI = A - p
print("compund interest = ", CI) 

3.  
""" Area of Triangle""" 

import math
a = eval(input("Enter first side? "))
b = eval(input("Enter second side? "))
c = eval(input("Enter third side? "))
s = (a + b + c) / 2
area = math.sqrt(s *(s-a)*(s-b)*(s-c)) 
print("Area = ", area)
4.
"""To check number is even or odd"""
num = eval(input("Enter any number ?"))
if num % 2 == 0:
        print ("EVEN NUMBER...")
else:
        print ("ODD NUMBER...")

5.  
"""Checking Divisibility """ 

a = eval(input("Enter first number? "))
b = eval(input("Enter second number? "))
if a % b == 0:
    print (a, " is divisible by ", b)
else:
    print (a, " is NOT divisible by ", b)

6.  
"""Roots of a Quadratic Equation""" 

import math as m
a = eval(input("Enter value for a ?"))
b = eval(input("Enter value for b ?"))
c = eval(input("Enter value for c ?"))
d = b ** 2 - 4 * a * c
if d >=0:
    r1 = (-b + m.sqrt(d))/ (2 * a)
    r2 = (-b - m.sqrt(d))/ (2 * a)
    print("Root1 = ", r1, "\nRoot2 = ", r2)
else:
    print("Root are imaginary")

7.  
"""Calculating grades on total marks""" 

tot_marks = eval(input("enter total marks obtained by student ? "))
percent = tot_marks / 5
if percent >= 90:
        grade = "A"
elif percent >= 75:
        grade = "B"
elif percent >= 60:
        grade = "C"
else:
        grade = "D"
print ("your percentage is ", percent, "and grade is : ", grade)

8.  
"""Calculating income Tax""" 

gs = eval(input("Enter gross salary : ?"))
if gs<=100000:
    it = 0
elif gs <=500000:
    it = (gs - 100000) * 10/100
elif gs <=1000000:
    it = 10000 + (gs - 500000) * 20/100
else: 
    it =  25000 + (gs - 1000000) * 30/100
print("Income tax to be paid = ", it) 

9. 
"""Maximum of 3 numbers""" 

a = eval(input("Enter value for a ?"))
b = eval(input("Enter value for b ?"))
c = eval(input("Enter value for c ?"))
if a>b:
     if a>c:
        max = a
     else
        max = c
else:
     if b>c:
        max = b
     else:
        max = c
print("Maximum = ", max)   

10.  
"""Finding absolute value """ 

num = eval(input("Enter any number :"))
num1 = num
if num < 0 :
    num1 = -1 * num      # we can also write it as num1 = -num
print("Absolute value of ", num, "is = ", num1) 

11.  
"""Printing even numbers between 1 to N"""

x = 2
N = eval(input("Enter the limit N? "))
while x <=N:
    print(x)
    x += 2 
12. 
"""Sum of Digits for a given number"""
Sum = 0; Rem=0
num = eval(input("Enter any number "))
while num > 0:
      Rem = num % 10
      Sum = Sum  + Rem
      num = num //10
print("Sum of digits = ", Sum)

13.  
"""Reverse of a number""" 

rev = 0; Rem=0
num = eval(input("Enter any number "))
while num > 0:
      Rem = num % 10
      rev = (rev * 10) + Rem
      num = num //10
print("Reverse of the given number = ", rev)

14.  
"""Factorial of a given number""" 

x = 1; fact = 1
N = eval(input("Enter the number N? "))
while x <=N:
    fact = fact * x
    x += 1
print("Factorial  of  ", N, "  = ", fact) 

15.  
"""Print Fibonacci series upto N terms """ 

a = 0; b=1; count = 2
N = eval(input("Enter number of terms to be printed"))
print ("Fibonacci series upto ", N, "terms are : ",a ,b, end = ' ')
while count < N:
       c = a + b;
       print(c, end = ' ')
       a= b;
       b = c
       count= count + 1 

16.  
"""Factorial of a given number""" 

N = eval(input("Enter any number :"))
fact = 1
for i in range(N, 1, -1):
    fact = fact * i
   
print("Factorial of ", N, " = ", fact)     

17. 
"""To check the given number is prime or NOT? """ 

flag = 1
N = eval (input("Enter any number : "))
for i in range(2, N):
    if ( N % i == 0):
        flag = 0
   
if(flag == 0):       
    print("Number", N, "is NOT Prime")
else:
    print("Number", N, "is Prime")

18. 
#Program to Sort 3 Numbers in ascending order 

a = eval(input("Enter value for a ?"))
b = eval(input("Enter value for b ?"))
c = eval(input("Enter value for c ?"))
if a<b :
    if a < c:
        if b<=c:
            print ("Numbers in ascending order are = ", a, b, c)
        else:
            print ("Numbers in ascending order are = ", a, c, b)
    else:
         
        print ("Numbers in ascending order are = ", c, a, b)
else:
    if b < c:
        if a<=c:
            print ("Numbers in ascending order are = ", b, a, c)
        else:
            print ("Numbers in ascending order are = ", b, c, a)
    else:
            print ("Numbers in ascending order are = ", c, b, a)

19.  
"""To Sum first N terms of the series 2/5 + 4/10 + 6/15 + 8/20 +... + N terms""" 

N = eval(input("Input number of terms to be sum : "))
num = 2
den = 5
sum = 0
for i in range(1, N+1):
     sum = sum + num/den
     num = num + 2
     den = den + 5
print("sum of first ", N , "terms = ", sum)
 
            OR 
N = eval(input("Input number of terms to be sum : "))
sum = 0
for i in range(1, N+1):
     sum = sum + (2*i)/(5*i)
print("sum of first ", N , "terms = ", sum) 

20.  
"""Calculating compound interest using loop""" 

P = eval(input("Enter value for Principle :"))
R = eval(input("Enter value for rate :"))
T = eval(input("Enter value for Time(in years) :"))
si = 0; ci = 0; amt = 0
amt = P;
for t in range(1, T+1):
    si = amt * R * 1/100
    amt = amt + si;
ci = amt - P
print("Compound Interest = ", ci) 

21.  
"""Multiplication table""" 

N = eval(input("Enter any number :"))
fact = 1
print("Multiplication table of ", N, "is : \n")
for i in range(1, 11):
   print(N , " X", i, "= ", N*i) 

22.  
"""Pattern 
   1 
   12 
   123 
   1234 
   12345"""  

for i in range(1, 6):
    for j in range(1,i+1):
       print(j, end = ' ')
    print() 

23. 
"""Pattern 
   1 
   22 
   333 
   4444 
   55555"""  

for i in range(1, 6):
    for j in range(1,i+1):
       print(i, end = ' ')
    print() 

24.  
"""Pattern 
   ***** 
   **** 
   *** 
   ** 
   * """  

for i in range(5, 0, -1):
    for j in range(i,0, -1):
       print("*", end = ' ')
    print()
   
25. 
"""Pattern 
           * 
          * * 
         * * * 
        * * * * 
       * * * * * """  

for i in range(1, 6):
    for k in range(10, i, -1):
        print(' ', end = '')
    for j in range(1,i+1):
       print("* ", end = '')
    print()

Comments

Popular posts from this blog

Data Management {CLASS XI}

Q: What is a Database? The collection of data is usually referred to as the DATABASE. The database maintains the information that help to the decision-making process in an organization. The same data in a database may serve many application. e.g.: A database of employees of an organization, Database of students of a school, etc. Database System It is basically a computer based record keeping system. The Relational Data Model In Relational data model, the data is organized into tables ( i.e. rows & cols). These tables are called relations. A row in a table represents a relationship among a set of values. Terminology in RDBMS The different terms used in the relational model are: 1.Relation 2.Tuples 3.Attributes 4.Degree 5.Cardinality 6.Domain 1. Relation A Relation is a table (i.e rows & cols) In above example (STUDENT) is a relation that has 4 rows (records) and 3 columns (fields). 2. Tuples The rows of a relation are gener...

PYTHON FUNDAMENTALS

                  Python Character Set                                                                              Tokens     Keyword      Identifiers (Names)   Literals   Operators   Punctuators                                       Keywords A keyword is a word having special meaning reserved by the programming language.                               More on keywords…. ¨ We cannot use a keyword as  variable name ,  function  name or any other identifier . ¨ In Python, keywords are case sensitive...
                                     CYBER SAFETY Introduction-Cyber Safety :- Cyber safety is the safe and responsible use of Internet & ICT(Information & Communication Technology). Cyber safety is about to not only keeping information safe and secure, but also being responsible with that information, being respectful of other people online. As per Cyber safety peoples are advised to use good 'netiquette' (internet etiquettes). Safely Browsing the Web :- Viruses and malware spread, easily and quickly through websites/web browsing. Through clicking over the links found on web pages or in email mistakenly our computer may be infected. An infected computer can run slow, barrage us with pop-ups, download other programs without our permission, or allow our sensitive personal information to others.  Tips for Safe Web Browsing   Common sense- (never respond...

TUPLES

The Python tuples are sequences that are used to store a tuple of values of any type. • Tuples are immutable. • Tuple is a type of sequence like string and list but it differs from them in way that lists are mutable but strings and tuples are immutable Creating and Accessing Tuples Tuples are depicted through parenthesis. () Empty tuple (1,2,3) Tuple of integers (2,3.5,6,7.5) Tuple of integer and float (‘ x’,’y’,’z ’) Tuples of characters Creating Tuples 1. Empty Tuple >>> t=tuple() >>> t () 2. Single Element >>> t=(1) >>> t 1 >>> t=3 , # to construct a tuple with one element just add comma >>> t (3,) 3. Long Tuples >>> t1=(11,22,33,44,55,66,77,88) >>> t1 (11, 22, 33, 44, 55, 66, 77, 88) >>> print (t1) (11, 22, 33, 44, 55, 66, 77, 88) 4. Nested Tuples : t=(11,22,(33,44),55) >>> t (11, 22, (33, 44), 55) Creating Tuple...

mysql connector

import mysql.connector import datetime mydb=mysql.connector.connect(host="localhost",\                              user="root",\                              passwd="root",\                              database="practicalexam") mycursor=mydb.cursor() def teacheradd():     L=[]     tno=int(input("Enter tno:"))     L.append(tno)     tname=input("Enter tname:")     L.append(tname)     tsalary=int(input("Enter tsalary:"))     L.append(tsalary)     value=L     value=(tno,tname,tsalary)     sql="insert into teacher(tno,tname,tsalary)values(%s,%s,%s)"     mycursor.execute(sql,value)     mydb.commit() def teachersearch():   ...

INTRODUCTION

Python is a general purpose interpreted , object oriented and high level programming language. It was created by  GUIDO VAN ROSSUM  in  FEBRUARY  1991. Python is based on or influenced with two programming languages : ABC Language Modula - 3 Features of python : Easy to learn Easy to read Easy to maintain Interactive mode Portable GUI Programming Some minuses of python : Not the fastest language Lesser libraries than C , Java , Perl Not strong on type-binding Not easily convertible List of companies using python for revenue generation : Google Youtube Torrent Intel Cisco HP IBM NASA Maya i-Robot
LIST (Class XI) • It is an ordered set of values enclosed in square brackets []. • Values in the list can be modified, i.e. it is mutable. • As it is set of values, we can use index in square brackets [] to identify a value belonging to it. • The values that make up a list are called its elements, and they can be of any type. . Its syntax is: Variable name [index] (variable name is name of the list). Let's look at some example of simple list: i) >>>L1 = [1, 2, 3, 4] # list of 4 integer elements. ii) >>>L2 = [“Delhi”, “Chennai”, “Mumbai”] #list of 3 string elements. iii) >>>L3 = [ ] # empty list i.e. list with no element iv) >>>L4 = [“ abc ”, 10, 20] # list with different types of elements v) >>>L5 = [1, 2, [6, 7, 8], 3] # A list containing another list known as nested list Creating and Accessing List • To create a list, put a number of expressions in square brackets. L=[] L=[value1, ...

queue

a=[] c= "y" while(c=="y"):     print("1. INSERT")     print("2. DELETE")     print("1. DISPLAY")     choice=int(input("Enter Your Choice:"))     if(choice==1):         b=input("Enter new number:")         a.append(b)     elif(choice==2):         if(a==[]):              print("Queue is Empty")         else:             print("Deleted value is:",a[0])             a.pop(0)     elif(choice==3):         length=len(a)         for i in range(0,length):      ...

stack

s=[] c="y" while(c=="y"):     print("1. PUSH")     print("2. POP")     print("3. DISPLAY")     choice=int(input("Enter your choice"))     if(choice==1):         a=input("Enter any number: ")         s.append(a)     elif (choice==2):         if(s==[]):             print("Stack Empty")         else:             print("Element Deleted is :",s.pop())      elif(choice==3):         l=len(s)         for i in range(l-1,-1,-1):             print(s[i])     else:  ...