Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/vol9_6/epizy.com/epiz_23948316/htdocs/wp-includes/script-loader.php on line 757

Notice: Trying to access array offset on value of type bool in /home/vol9_6/epizy.com/epiz_23948316/htdocs/wp-includes/theme.php on line 2360

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/vol9_6/epizy.com/epiz_23948316/htdocs/wp-includes/load.php on line 986
PYTHON CODES AND PROGRAMS – Tech Savvy

PYTHON CODES AND PROGRAMS

Tech Savvy Experts here to help you....


TO FIND LARGER NO

 #which no is larger
 a = float (input ( "Enter a no."))
 b = float (input ( "Enter other no."))
 if (a<b):
     print (" b is the larger no")
 elif (a==b):
     print ("Both no are equal")
 else:
     print ("a is the larger no")

TO FIND VALUE OF SINE 0,30,45,60,90

 #value of sine of 0,30,45,60,90
 a= float( input ("Enter a sin value"))
 if a==0:
     print ("0")
 elif a==30:
     print ("0.5") 
 elif a==45:
     print (2(-0.5))  elif a==60:     print (3(0.5))/2 
 elif a==90:
     print ("1") 

TO MAKE A PHYSICS CALCULATOR

 #physics calculator
 print ("This is a physics calculator so please enter all basic              fundamental units first")
 M=(int(input ("Enter mass")))
 L=(int(input ("Enter length")))
 T=(int(input ("Enter time")))
 mol=(int(input ("Enter amount of substance")))
 cand=(int(input ("Enter luminous intensity")))
 K=(int(input ("Enter temperature")))
 I=(int(input ("Enter electric current")))
 print("To check")
 a=(int(input("Velocity press 1")))
 if (a==1):
     print("For velocity is",L/T )
 b=(int(input("For Acceleration press 2")))
 if (b==2):
     print("Acceleration is",(L)/(T**2) )
 c=(int(input("For Force press 3")))
 if (c==3):
     print("Force is",ML(T**-2) )
 d=(int(input("For Pressure press 4")))
 if (d==4):
     print("Pressure is", M*(L-1)(T-2) )
 e=(int(input("For Work press 5")))
 if (e==5):
     print("work is",M*(L2)(T-2))

TO USE IMPORT MATH

.
               import math
       print (math.sqrt(9))
       3.0
       print (math.sqrt(2))
       1.4142135623730951
       print (math.log10(10))
       1.0
       print (math.log(2.71))
       0.9969486348916096
       print (math.tan(math.log10(10)))
       1.5574077246549023
       print (math.tan(1))
       1.5574077246549023
       from math import log,sqrt
       print(sqrt(9))
       3.0         

TO DISPLAY CURRENT DATE AND TIME

from datetime import datetime
 n = datetime.now()
 print("Current date and time = ", n)

TO GIVE VALUE OF X FOR ANY QUADRATIC FUNCTION

import math
 x=(int(input("Enter a no")))
 def f(x):
     return pow(x,2)+(5*x)+5
 print ("value of x^2+5x+5=",(f(x)))

TO FIND FACTORIAL

n=int(input("Enter the no whose factorial you want to find"))
 for i in range(n-1,1,-1):
   n=n*i
 print(n)

FOR FIBONACCI SERIES

a=1
 b=1
 i=1
 n=(int(input ("Enter till what no you want the fibonacy series")))
 while i<n+1:
     print(a)
     a,b=b,a+b
     i+=1

TO FIND VALUE OF AND POLYNOMIAL

import math
 a=(int(input("""----POLYNOMIAL PROGRAM---
 Which order of polynomial you are using---
 =>""")))
 count=1
 h=1
 x=(int(input("Firstly Enter the value of x  =  ")))
 c=1
 while a>0 :
     fx=(int(input(f"Enter coefficent of x^{a} = ")))
     b=(fx*pow(x,a))
     a=a-1
     count+=1
     while count==2:
         c=b
         d=c
         break
     while count>2:
         d=b+c
         c=d
         break
     print(d)
 const=(int(input("Enter the value of constant  =  ")))
 print (f"Value of polynomial is = {d+const}")

TO ARRANGE 3 NOS IN DECREASING ORDER

n_1=int(input("Enter the first no."))
 n_2=int(input("Enter the secound no."))
 n_3=int(input("Enter the third no."))
 if n_1>n_2>n_3:
     print ("descending order",n_1,">",n_2,">",n_3)
 elif n_1>n_3>n_2:
     print ("descending order",n_1,">",n_3,">",n_2)
 elif n_2>n_1>n_3:
     print (f"descending order",n_2,">",n_1,">",n_3)
 elif n_2>n_3>n_1:
     print (f"descending order",n_2,">",n_3,">",n_1)
 elif n_3>n_1>n_2:
     print (f"descending order",n_3,">",n_1,">",n_2)
 elif n_3>n_2>n_1:
     print (f"descending order",n_3,">",n_2,">",n_1)

TO DISPLAY PARTICULAR PATTERN OF NOS

n=int(input("Enter"))
 for i in range(1,n+1):
    for j in range (1,i+1):     
        print(j,end=" ")

PROGRAM 2—

n=int(input("Enter a no"))
 for i in range (1,n+1):
    for j in range (1,i+1):     
       if (j==i) or (j==n+1-i):            
            print (i,end ="")    
       else:         
           print(" ",end=" ")
    print("")

PROGRAM TO PRINT DIFFERENT PATTERNS

import time
 print("Welcome, This is pattern program")
 print("LOADING….")
 time.sleep(1)
 print("For starting program press Y")
 print("To exit press N")
 to=input()
 if to=="Y" or to=="y":
     print("There are a few types of patterns that we can print")
     print("Flashing you all possible patterns")
     print("" "")
option=int(input("Enter your choice"))
n=int(input("Enter no"))
if option ==1:
    for i in range (1,n+1):
        for j in range (1,n+1):
            if  j==1 or i==1 or j==n-i+1 or j==i or j==n or i==n:
                print("*",end=" ")
            else:
                print(" ",end=" ")
        print("")

if option==2:

    for i in range (1,n+1):
        for j in range (1,n+1):
            if   j==n-i+1 or j==i :
                print("*",end=" ")
            else:
                print(" ",end=" ")
        print("")

if option==3:
    for i in range (1,n+1):
        for j in range (1,n+1):
            if  j==1 or i==1 or  j==n or i==n:
                print("*",end=" ")
            else:
                print(" ",end=" ")
        print("")

if option==4:

    for i in range (1,n+1):
        for j in range (1,n+1):
            if  j==n-i or j==i+1 :
                print(" ",end=" ")
            elif j==n-1 or i==n-1 or  j==-n or i==-n:
                print("*",end=" ")
        print("")

if option==5:

    for i in range (-40,42):
        for j in range(-40,42):
            if j==1 or i==1:
                print("*",end= " ")
            elif j==4+i:
                print("#",end=" ")
            else:
                print(" ",end=" ")
        print("")
if to=="n" or to=="N":
     print("Thankyou")

A PROGM TO CHECK WHETHER A NO IS PRIME OR NOT

a = (int(input("Enter a no")))
 count=0
 for  b in range (1, a+1):
     if a%b==0:
         count=count+1
 if count<=2:
     print("It's prime" )
 else:
     print("It's not prime")

TO MAKE A RANDOM NO GAME(FUN!!!)

import random
 import time
 count=0
 print("-----IT'S A RANDOM NO GUESSING GAME-----_")
 m=int(input("---IN HOW MANY GUESSES YOU WOULD BE ABLE TO GUESS THE NO---"))
 n=int(input("Enter a random no between 1 to 100"))
 while ValueError:
     n=int(input("enter again"))
 random=(random.randint(1,100))
 while countn:
             n=int(input("Enter high"))
             count+=1
         if random=m:
     print ("You Loose")
     break
 if n==random:
    print("YOU CRACKED IT")
 

PROGRAM TO PRINT SQUARE TILL NO. ENTERED BY USER

import math
 n=int(input("Enter no. till what you want sum of the squares"))
 count=1
 for i in range (1,n+1):
     a=pow(i,2)
     if count==1:
         b=a
         count=count+1
if count>1:
    b=a+b
    count=count+1
print(b-1)

PROGRAM TO ADD RECIPROCALS(1+1/2+1/3+1/4…1/n)

n=int(input("Enter the no"))
 sum=0
 for i in range (1,n+1):
     sum=sum+(1/i)
 print (sum)

program 2--
n=int(input("Enter the no"))
Sum=0
m=1
for i in range (1,n+1):
    for j in range(1,i+1):
          m=m*j

          Sum=Sum+(1/m)
print(Sum)


PRGM TO PRINT SUM OF ODD NOS TILL NO ENTERED BY USER

n=int(input("Enter a no till what you want sum of odd nos"))
 for i in range (n,1):
     n=n+i
 print(i)

PROGRAM TO PRINT VALUE OF (1/1! + 2/2! + 3/3! +… + n/n!)

n=int(input("Enter"))
 s=0
 fact=1
 for i in range (1,n+1):
     fact=fact*i
     s=s+(i/fact)
     if i==n:
         print("(",i,"/",i,"!)",end="  ",sep="")
     else:
         print("(",i,"/",i,"!)",end=" + ",sep="")
 print("=",s)

PROGRAM TO REPLACE CHARACTERS IN A STRING

def Function():
     n=(input("Enter a word"))
     word=list(n)
     l=len(n)
     print("select 1,2,3 to convert upper case, lower case, both characters respectively ")
     m=int(input("Enter your choice"))
     if m==1:
         char1=input("Enter what you want in place of upper character")
     if m==2:
         char2=input("Enter what you want in place of lower character")
     if m==3:
         char1=input("Enter what you want in place of upper character")
         char2=input("Enter what you want in place of lower character")
     for i in range (0,l):
         wor=word[i]
         if m==1:
             if wor.isupper():
                 word[i]=char1
         elif m==2:
             if wor.islower():
                word[i]=char2
         elif m==3:
             if wor.islower():
                 word[i]=char2
             if wor.isupper():
                 word[i]=char1
     abc=""
     print(abc.join(word))
     print("Continue?")
     cont=input()
     if cont=="yes" or cont=="y":
         Function()
     elif cont=="no" or cont=="n":
         print("bye")
Function()

PRGM TO COUNT NO OF UPPER, LOWER CASE LETTERS, DIGIT OR SPECIAL CHARACTERS IN A STRING

a=str(input("Enter a word"))
 upper=0
 lower=0
 digit=0
 special=0
 z=len(a)
 for i in range (0,z):
     b=a[i]
     if b.isupper():
         upper+=1
     elif b.islower():
         lower+=1
     elif b.isdigit():
         digit+=1
     else:
         special+=1
print(f"No. of upper case character =",upper)
 print(f"No. of lower case character =",lower)
 print(f"No. of digit character =",digit)
 print(f"No. of special character =",special)        

Leave a Reply

Your email address will not be published. Required fields are marked *