3.Python(Components of a Program)
3.Python(Components of a Program)
print(x)
x=25
print(x)
so to correct the code:
x=0
print(x)
x=25
print(x)
Creating variables
Student_name = 'Arun' # Assignment statement where “=” is the
assignment operator.
Age=16
Percentage=98.5
print(Student_name, Age, Percentage)
Multiple assignments:
1. Assigning same value to multiple variables:
a=b=c=10
2. Assigning multiple value to multiple variables
x,y,z=10,20,’hello’
It will assign the value order wise i.e., first variable is given first
value, second variable second value and so on.
Point to note: x,y=20 will throw syntax error. This type of
assignment is not allowed
Dynamic Typing
A variable pointing to a value of certain type can be made to point to
value of different type by reassigning the value. This is called dynamic
typing. Note: type() help us to understand this
a=10 # numeric value integer
a="welcome" #string value
a="hello"
print(type(a))
a=5
print(type(a))
a = 2.0
print(type(a))
a = 1+2j
print(type(a))
Example
Output
Example
output
Example
a=10
print(type(a))
Output:
<class 'int'>
Example
print("hello") # string
print(17.5) # number
r=3
print(3.14*(r*r)) # result of a calculation
print("I\'m",12+5,"years old.")
print("hello all \
welcome to class XI") # ‘\’ slash prints the string in the same
line
print("hello all", end=' ') # prints the line with the string specified with
the end argument -- space
print("welcome to python class")
print("hello all", end='\n') # prints the line with the string '\n' denoted
new line
print("welcome to coding class")
print("hello all",end='$') # prints the line with the string specified with
the end argument '$"
print("Have fun coding")
print("My","name","is","Amit",sep="@#") # print the string with the
specified separator argument
Output
hello
17.5
28.26
hello all
Program : Write a python program to find the sum of two number. The
number should be a user input.
a=int(input("enter the value of a"))
b=int(input("enter the value of b"))
c=a+b
print("First number",a)
print("Second number",b)
print("sum of two number",c)
ii. x,y=7,2
x,y,x=x+1,y+3,x+10
print(x,y)
iii. a,b=2,6
a,b=b, a+2
print(a,b)
iv. a,b=2,6
print(print(a+b))
v. x,y,z=10,20,3
p,q,r=z-5, x+3, y-4
print('x,y,z:',x,y,z)
print('p,q,r:',p,q,r)
vi. x=10
x=x+10
x=x-5
print(x)
x,y=x-2,22
print(x,y)