Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, 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:-


 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.

variable datatype will be managed by the assigned value. Python variable type and memory allocation depend on assigned data .we can hold multiple types for variables in a single 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,b,c = 10,20,30



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


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.


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.

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

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

const = (3.14,2.2,"")

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:-

a,b = b,a
print("a=",a," b= ",b)

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

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


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
pf =-500
hra = 300

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


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?

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