Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Variable, Constant, and Literals Declaration in Python:-


Variable:- 

 it is an identifier that is used to contain values in the program. variable value and type can be changed in the program at run time.


Python
variable datatype will be managed by the assigned value. Python variable type and memory allocation depend on assigned data .we can provide multiple data types for a single variable in the python program.


Python variable is a
loosely coupled type declaration so that we can change variable datatype in the program.


The syntax for Variable Declaration in Python:-

identifier=value  #single value 
identifier1,identifier2,...= value1,value2,..   #multiple variable, multiple value

a=10
a,b,c = 10,20,30

a,b=10,20

print(a+b)

Example of variable:-

a,b = input("enter first number"),input("enter second number")
print(a+b)   #  "10"+"20"  "1020"
print(int(a)+int(b))  # 10+20
print(int(a+b))    #  1020  int

print(int(a)+float(b))   


the naming convention of variable:-

variable name always will be started by alphabets, without using space, keyword.
the variable identifier will be declared in the lower case according to the python naming convention.




Constant:-

it is a special identifier in the Python program whose values can not be changed dynamically.
Python provides a
list of the constant that is called a tuple.


tuple
variable value can not be modified  in the program and outside from the program


identifier = (value1,value2,value3,..)


const = (3.14,2.2,"http://www.shivaconceptsolution.com")


Literals:-  It is the value of variable and constant for example if we assign 

a=2   # 2 is the integer  type literals

b = 3.14 # 3.14 is the float type literals

print("hello")  # hello is the string type literals


Example of Literals:-

print(10+20)    #10,20 is the integer type literals
print("hello"+"how r u")   # hello, how r u is the string type literals

WAP to reverse a five-digit number without using a loop?

num=45123
a = num%10  #3
num=num//10 #4512
b=num%10  #2
num=num//10 #451
c=num%10 #1
num=num//10 #45
d=num%10 #5
e=num/10   #4
num1 = a*10000 + b*1000+c*100+d*10+e*1
print(num1)


ASSIGNMENT:-

1) WAP to calculate the total salary of an employee where basic, ta, da, comm, pf,hra, leave will be entered by the users?


basic:-  12000
ta  400
da=200
comm=500
pf =-500
hra = 300
leave=3


2)  WAP to calculate electricity bill where unit price, total consumption, the extra load will be entered by the users?

Solution:-

up= float(input("enter price"))

cons= float(input("enter consumption"))

load = float(input("enter unit for extra load"))

bill = up*cons+ 2*(up*load)

print("Total bill is "+str(bill))

print("Total consumption without load"+str(up*cons))

print("Total consumption with extra load"+str(2*(up*load)))  


3
WAP to calculate Simple Interest where rate and time will be constant and 
the principal will be an integer?


4 WAP to calculate the area of a triangle, circle, and rectangle in the same program where the value of pi, the base of the triangle, and the height of the rectangle will be constant.

5)  WAP to convert temperature from  Celsius to Fahrenheit?




15 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. num=54231
    a=num%10
    num=num//10
    b=num%10
    num=num//10
    c=num%10
    num=num//10
    d=num%10
    num=num//1=
    e=num%10
    num2=a*10000+b*1000+c*100+d*10+e*1
    print(num2)

    ReplyDelete
  2. area of circle
    r=2
    const=(3.14)
    area=(const*r*r)
    print(area)

    ReplyDelete
  3. area of hexagon
    a=2
    const=(3*1.732//2)
    print(area)

    ReplyDelete
  4. factorial of a number
    n=5
    fact=(5*4*3*2*1)
    print(fact)

    ReplyDelete
  5. calculate compund interst
    p=1000
    r=4
    n=5
    t=4
    c=(p*(1+r//n)*n*t)
    print(c)

    ReplyDelete
  6. WAP to calculate Simple Interest where rate and time will be constant and
    the principal will be an integer?
    p=1000
    r=2
    t=5
    const=(r,t)
    si=(p*r*t)
    print(si)

    ReplyDelete
  7. WAP to calculate the area of a triangle, circle, and rectangle in the same program where the value of pi, the base of the triangle, and the height of the rectangle will be constant
    area of traingle the base of traingle is constant
    b,h=10,20
    const=(b)
    area=(const*h)//2
    print(area)
    area of circle where pi is const
    r=2
    const=(3.14)
    area=(const*r*r)
    print(area)
    area of rectangle where hight is const
    b,h=20,30
    const=(h)
    area=(b*const)
    print(area)

    ReplyDelete
  8. Solution of Temperature converter
    c=45
    f = (9*c+160)/5
    print(f)

    ReplyDelete
  9. #PYTHON(6 To 7 PM Batch)
    #For the Calculation of area of a triangle, circle, and rectangle in the same program

    a= int(input("For AREA of Triangle Press 1:\nFor AREA of Rectangle Press 2:\nFor AREA of Circle Press 3:\t"))
    if a==1:
    print("\nBASE = 20")
    h=int(input("Enter Height:\t"))
    b=20
    print("AREA of Triangle :\t",(b*h)/2)
    elif a==2:
    print("\nLENGTH= 20")
    w=int(input("Enter WIDTH:\t"))
    l=20
    print("AREA of Rectangle:\t",(w*l))
    elif a==3:
    print("\nπ=3.14")
    pi=3.14
    r=int(input("Enter the Radius:\t"))
    print("AREA of Circle:\t",(pi*r*r))
    else:
    print("Entered wrong Option")

    ReplyDelete
  10. # PYTHON( 6 To 7 PM BATCH)
    # Program to convert temperature from Celsius to Fahrenheit or Vice Versa

    z = input("Press C or c to know temprature in Celsius :\t""\nPress F or f to know Temprature in Fahrenheit:\t")

    if z == 'c'or z=='C':

    f = int(input("Enter Temprature in Fahrenheit:\t" ))
    print("Temprature in(°F):\t",f,"°F")
    print("Temprature in(°C):\t",(f-32)*5/9,"°C")

    elif z=='f' or z=='F':
    c = int(input("Enter Temprature in Celsius:\t" ))
    print("Temprature in(°C):\t",c,"°C")
    print("Temprature in(°F):\t",(c*9/5)+32,"°F")

    else:
    print("\nEntered Wrong Option")

    ReplyDelete
  11. Adarsh dixit
    principal = int(input('enter principal amount:'))
    ratei = float(input('enter rate of intrest:'))
    numy = float(input('enter num of years:'))

    simpleinterest = (principal * ratei * numy)/100

    print('simple interest: {0}'.format(simpleinterest))

    ReplyDelete
  12. Adarsh dixit
    sno=int(input('enter service number'))
    cname=input('enter cust name')
    ore=int(input('enter old reading'))
    nre=int(input('enter new reading'))
    units=nre-ore
    if units<=100:
    amount=units*0.90
    surcharges=25
    elif units>100 and units<=300:
    amount=units*1.50
    surcharges=35
    elif units>300 and units<=500:
    amount=units*2.75
    surcharges=45
    elif units>500:
    amount=units*4.50
    surcharges=100
    netamount=amount+surcharges
    print('electrical info is:')
    print('meter number=',sno)
    print('name of cust=',cname)
    print('old reading=',ore)
    print('new reading=',nre)
    print('total numbers of units=',units)
    print('net payable amount=',netamount)

    ReplyDelete
  13. c=int(input('enter a celsius'))
    f = (9*c+160)/5
    print(f)

    ReplyDelete
  14. # PYTHON (6 To 7 PM BATCH)
    # Program to Calculate and Display Salary Slip of an employee.

    c = input("Company name :-")
    e = str(input("Employee name :-"))
    eid = input("Employee ID. :-")
    b = int(input("Basic Salary :-"))
    co = int(input("Medical Allowance :-"))
    d = int(input("Dearness Allowance :-"))
    t = int(input("Other Allowance :-"))
    h = int(input("HRA :-"))
    o = int(input("Over Time :-"))
    pf = int(input("PF :-"))
    esi = int(input("ESI :-"))
    tax = int(input("Professional Tax :-"))
    gross = b + co + d + t + h + o
    ded = pf + esi + tax
    net = (gross - ded)
    print("Company name :-\t", c)
    print()
    print("Employee name :-\t", e)
    print()
    print("Employee ID. :-\t", eid)
    print()
    print("Gross Earnings (A) :-\t", gross)
    print()
    print("Gross Deductions (B) :-\t", ded)
    print()
    print("Net Salary Payable (A-B) :-\t", net)
    print()

    st = str(net)
    sd = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"];
    print("Net Salary Payable(in words):-\t", end='')
    for i in st:

    if i == "0":
    print(sd[0], "", end='')
    elif i == "1":
    print(sd[1], "", end='')

    elif i == "2":
    print(sd[2], "", end='')
    elif i == "3":
    print(sd[3], "", end='')
    elif i == "4":
    print(sd[4], "", end='')
    elif i == "5":
    print(sd[5], "", end='')
    elif i == "6":
    print(sd[6], "", end='')
    elif i == "7":
    print(sd[7], "", end='')
    elif i == "8":
    print(sd[8], "", end='')
    elif i == "9":
    print(sd[9], "", end='')
    else:
    print("SomeThing Went Wrong")
    print("Only")

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post