EXERCISES 21 Same the final valve stored in the integer variable Safter execution of following statement for the was of 2017 - 13 and G) = 12. y = 21. S=*>y?xyl
Answers
Answer:
a) (20 + (-10)) < 12
b) num3 <= 24 or not(num3 > 24)
c) (6.75 >= num1) and (6.75 <= num2)
d) (middle > first) and (middle < last)
e) len(Stationery) == 0
Answer:
Serial_no.: Invalid - Identifier in python cannot contain any special character except underscore(_).
ii) 1st_Room: Invalid - Identifier in Python cannot start with a number.
iii) Hundred$: Invalid - Identifier in Python cannot contain any special character except underscore(_).
iv) Total Marks: 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 underscore ( _ ), instead of space.
v) Total_Marks: Valid
vi) total-Marks: 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 underscore ( _ ), instead of a hyphen ( - ).
vii) _Percentage: Valid
viii) True: Invalid - Identifier in Python should not be a reserved keyword.
Page No 115:
Question 2:
Write the corresponding Python assignment statements:
a) Assign 10 to variable length and 20 to variable breadth.
b) Assign the average of values of variables length and breadth to a variable sum
c) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.
d) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.
e) 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.
ANSWER:
a) length, breadth = 10,20
b) sum = (length + breadth)/2
c) stationary =['Paper','Gel Pen','Eraser']
d) first,middle,last = "Mohandas","Karamchand","Gandhi"
e) fullname = first +" "+ middle +" "+ last
Page No 115:
Question 3:
Write logical expressions corresponding to the following statements in Python and evaluate the expressions (assuming variables num1, num2, num3, first, middle, last are already having meaningful values):
a) The sum of 20 and –10 is less than 12.
b) num3 is not more than 24
c) GOOD MORNING
Page No 118:
Question 17:
Write a program to find average of three numbers.
ANSWER:
Program:
#defining three variables
a = 5
b = 6
c = 7
#calculating average using the formula, average = (sum of variables)/(number of variables)
average = (a + b + c)/3
#print the result
print("The average of",a,b,"and",c,"is",average)
OUTPUT:
The average of 5 6 and 7 is 6.0