CH - 5 TB Ex - Python Pgms
CH - 5 TB Ex - Python Pgms
i Serial_no. v Total_Marks
ii 1st_Room vi total-Marks
iii Hundred$ vii _Percentage
iv Total Marks viii True
i. Invalid - Identifier in python can't contain any exceptional character aside from underscore
(_).
ii. Invalid - Identifier in Python can’t begin with a number.
iii. Invalid - Identifier in Python can't contain any uncommon character aside from underscore
(_).
iv. Invalid - Identifier in Python can't contain any exceptional character aside from underscore
(_). In the event that more than a single word is utilized as a variable, at that point it tends to
be isolated utilizing underscore (_), rather than space.
v. Valid
vi. Invalid - Identifier in Python cannot contain any special character except underscore (_). If
more than one word is used as a variable then it can be separated using an underscore (_),
instead of hyphen (-).
vii. Valid
viii. Invalid - Identifier in Python should not be a reserved keyword.
(20+(-10))<12
10<12
True
d) The string ‘middle’ is larger than the string ‘first’ and smaller than the string ‘last’.
len(Stationery)==0
(0==(1==2)
1==2 (false)
False can be represented as 0
0==0 (True)
b) 2 + 3 == 4 + 5 == 7
(2+(3==4)+5)==7
3==4 (false)
2 +0 + 5 =7
7==7 (True)
c) 1 < -1 == 3 > 4
(1<-1)==(3>4)
(False) (False)
0==0 (True)
5. Write the output of the following:
a) num1 = 4
num2 = num1 + 1
num1 = 2
print (num1, num2)
Output: 2,5
b) num1, num2 = 2, 6
num1, num2 = num2,
num1 + 2
print (num1, num2)
Output: 6,4
c) num1, num2 = 2, 3
num3, num2 = num1,
num3 + 1
print (num1, num2, num3)
Output: Error, because num3 is used in RHS of line 2 (num3,num2=num1,num3+1) before defining
it earlier.
6. Which data type will be used to represent the following data values and why?
4(3+2) = 45 = 1024
55
e) print (4.00/(2.0+2.0))
(4.00/4.0)=1.0
f) num1 = 2+9*((3*12)-8)/10
print(num1)
2+9*(36-8)/10
=2+9*28/10
=2+252/10
=2+25.2
=27.2
g) num1 = 24 // 4 // 2
print(num1)
6//2=3
h) num1 = float(10)
print (num1)
10.0
i) num1 = int('3.14')
print (num1)
j) print('Bye' == 'BYE')
As Python compares string character to character and when different characters are found then
their Unicode value is compared. The character with a lower Unicode value is considered to be
smaller. Here, ‘y’ has Unicode 121 and ‘Y’ has 89. Output will be False.
True
LHS=10+6*4!=9//4-3
=10+6*4!=2-3
=10+6*4!=-1
=10+24!=-1
=34!=-1 (True)
RHS= 29>=29/9
29>=3.2 (True)
Output: True
RHS= true
Output: True
a) 25 / 0 - Run-time Error
OUTPUT:
***************************