PYTHON LAB
I PU COMPUTER SCIENCE
ASSIGNMENT - 1
1. Which of the following identifier names are invalid and why?
i Serial_no. v Total_Marks
ii 1st_Room vi total-Marks
iii Hundred$ vii _Percentage
iv Total Marks viii True
Output:
i v
ii vi
iii vii
iv viii
2. Write the corresponding Python assignment statements:
a) Assign 10 to variable length and 20 to variable breadth.
Output:
b) Assign the average of values of variables length and breadth to a variable sum.
Output:
c) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and
last.
Output:
d) Assign the concatenated value of string variables first, middle and last to variable
fullname. Make sure to incorporate blank spaces appropriately between different parts
of names.
Output:
3. Write logical expressions corresponding to the following statements in Python and
evaluate the expressions (assuming variables n1, n2, n3, first, middle, last are
already having meaningful values):
a) The sum of 20 and –10 is less than 12.
Output:
b) n3 is not more than 24.
Output:
c) 6.75 is between the values of integers n1 and n2.
Output:
4. Add a pair of parentheses to each expression so that it evaluates to True.
a) 0 == 1 == 2
1
PYTHON LAB
Output:
b) 2 + 3 == 4 + 5 == 7
Output:
c) 1 < -1 == 3 > 4
Output:
5. Write the output of the following:
a) num1 = 4
num2 = num1 + 1
num1 = 2
print (num1, num2)
Output:
b) num1, num2 = 2, 6
num1, num2 = num2, num1 + 2
print (num1, num2)
Output:
c) num1, num2 = 2, 3
num3, num2 = num1, num3 + 1
print (num1, num2, num3)
Output:
6. Give the output of the following when num1 = 4, num2 = 3, num3 = 2
a) num1 += num2 + num3
print (num1)
Output:
b) num1 = num1 ** (num2 + num3)
print (num1)
Output:
c) num1 **= num2 + num3
print (num1)
Output:
d) num1 = '5' + '5'
print(num1)
Output:
e) print(4.00/(2.0+2.0))
Output:
f) num1 = 2+9*((3*12)-8)/10
2
PYTHON LAB
print(num1)
Output:
g) num1 = 24 // 4 // 2
print(num1)
Output:
h) num1 = float(10)
print (num1)
Output:
i) num1 = int('3.14')
print (num1)
Output:
j) print('Bye' == 'BYE')
Output:
k) print(10 != 9 and 20 >= 20)
Output:
l) print(10 + 6 * 2 ** 2 != 9//4 -3 and 29 >= 29/9)
Output:
m) print(5 % 10 + 10 < 50 and 29 <= 29)
Output:
n) print((0 < 6) or (not(10 == 6) and (10<0)))
Output: