Page 143 - Computer Science Class 11 With Functions
P. 143
3. Swastik wants to test the programming knowledge of his friend. He has asked him to write a program to accept distance in
kilometers and display it in miles. His friend finally has written the following program:
miles = int('Enter the value of distance in miles')
kiloMeters = Miles/0.6213
print('miles: ' + miles + 'Kilometers: ' + kiloMeters)
The program written by Swastik's friend is not executing because it has errors. Now Swastik has to identify each error and
explain the same to his friend. Help him complete the task.
Ans. miles = int(input('Enter the value of distance in miles')) # input() was missing
kiloMeters = miles/0.6213 #inconsistent use of uppercase.
print('miles: ', miles, 'Kilometers: ', kiloMeters)
#comma is to be used to separate values instead of +
4. Gurleen is in class XI. She has taken her unit tests and is awaiting the result. She wants to write a program in Python that
accept marks in three subjects and calculates the average marks. Help her to write the program.
Ans. m1 = int(input('Enter marks in Subject 1 : '))
m2 = int(input('Enter marks in Subject 1 : '))
m3 = int(input('Enter marks in Subject 1 : '))
avgMarks = (m1+m2+m3)/3
print('Average Marks is ', avgMarks)
Assessment
A. Multiple Choice questions
1. The words that have special meaning for a Python interpreter are called _________________.
a. Literal b. Keyword c. Variable d. Token
2. Which of the following is a keyword in Python?
a. print b. Input c. PRINT d. None of these
3. Which of the following is a valid identifier?
a. Amrit singh b. #AmritSingh c. _AmritSingh d. Amrit&Singh
4. Which of the following always refers to a fixed value in Python?
a. Token b. Literal c. Keyword d. Operator
5. Which of the following is an escape sequence for a tab character?
a. \t b. \b c. \a d. \n
6. Which of the following is not an arithmetic operator?
a. * b. ** c. == d. //
7. Which of the following is a relational operator?
a. ** b. == c. // d. =
8. Which of the following operators is used to associate a data value with its variable?
a. == b. and c. != d. =
9. Which of the following is NOT true about variables?
a. A variable does not have a type associated with it.
b. A variable gets associated with the type of the object it refers to.
c. An identifier may denote a variable.
d. A variable is not declared explicitly.
Basics of Python Programming 141

