0% found this document useful (0 votes)
26 views3 pages

Answer Key Introduction To Python

The document is an answer key for an Introduction to Python exercise, providing correct answers for multiple-choice questions, fill-in-the-blanks, true/false statements, and descriptive questions. It covers key concepts such as features of Python, data types, input/output functions, statements vs. expressions, variable naming rules, loops, lists, and list methods. The content serves as a comprehensive review of fundamental Python programming concepts.

Uploaded by

yarabhengra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Answer Key Introduction To Python

The document is an answer key for an Introduction to Python exercise, providing correct answers for multiple-choice questions, fill-in-the-blanks, true/false statements, and descriptive questions. It covers key concepts such as features of Python, data types, input/output functions, statements vs. expressions, variable naming rules, loops, lists, and list methods. The content serves as a comprehensive review of fundamental Python programming concepts.

Uploaded by

yarabhengra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Answer Key

Introduction to Python

Exercises

A. Tick (✓) the correct answers.

1. b. 2. a. 3. c. 4. b. 5. a. 6. c. 7. a. 8. c. 9. b. 10. c.

B. Fill in the blanks. 1. List 2. letter; underscore 3. keyword 4. Indentation 5. arithmetic


operator 6. float 7. .py 8. and 9. 100 10. while

C. Write T for True and F for False. 1. F 2. T 3. F 4. F 5. T 6. T 7. F 8. F 9. T 10. F

D. Answer the following questions. 1. The three features of Python are as follows:

a. Easy-to-code: Python is a very easy-to-learn language as compared to other programming


languages in terms of its syntax, which makes writing a code easier.

b. Open-source: Python is an open-source programming language meaning that its source


code is available online for free and anyone can modify its code and contribute to its
development. Python also has an online forum where people can share their views to
improve the language further.

c. Cross-platform Language: Python is a cross-platform language, which means that the same
Python program can be run on different operating systems.

2. An arithmetic operator is a mathematical function that takes one or two operand(s) and
performs a calculation, such as addition, subtraction, and so on. For example, let us take the
values of the variables x and y to be 10 and 3 respectively and execute the following lines of
code. z = x + y print (z) This will give the output as 13. Relational operators are used for
comparing two values to establish greater than, less than, equal to, or more relationships
between them. For example, let us take the values of the variables x and y to be 10 and 30
respectively and execute the following line of code. z = x > y This will give the output as
False.

3. The different types of data available in Python are:

a. Integer type: Integer (int) data type can store only whole numbers without a fractional
part. An integer can be both a positive and a negative number. For example, +20, ̶ 35, and 10
are some integers.

b. Float type: Float (float) data type is used for storing numbers having a fractional part. For
example, 10.11, -65.981, 6e2 are some floating-point values.

c. String type: String (string) is a sequence of characters where each character can be an
alphabet, a number, or any other special character. In Python, strings can be enclosed in
single or double quotation marks. For example, 'I am learning Python' is the same as "I am
learning Python".

4. The input( ) function is used to read input from the user. Using the input( ) function, the
user can enter information. The use of this function makes the program interactive, while
the print( ) function prints the specified message on the screen or any other output device.
5. a. Statements: A statement is an instruction that Python can execute. On execution of a
statement, an action takes place. For example, print ("Python") is a statement. It prints the
string "Python" on the screen

. b. Expressions: An expression is a combination of values, variables, operators, and function


calls that need to be evaluated before execution and returns a result value. For example, a +
b = 10 is an expression.

c. Keywords: These are the names assigned to specific values in python. For example, if, else,
not, and so on.

d. Identifiers: An identifier is a name used to identify a function, variable, class, module, or


any other object. Identifiers in Python start with a letter or an underscore (_), which can be
followed by letters, underscores, or digits.

6. Variables are the reserved memory locations to store data values. These values can be
changed during the program execution and that is why these are called variables, meaning
something that can vary or change

The rules for naming a variable are as follows:

A variable’s name must always start with either a letter or an underscore (_). For example,
car, _car, and so on.

A variable’s name cannot start with a digit. For example, 9car is not a valid variable, but car9
is a valid variable.

A variable’s name cannot have special characters such as #, $, &, and so on. They can only
contain alphanumeric characters and underscores (A to Z, 0-9, a to z, or _). For example,
_car10 is a valid variable, whereas $car10 is invalid.

Python is a case-sensitive language, which means ‘car’ and ‘CAR’ are two different variable
names in Python. A variable cannot be used as a valid identifier. For example, True is a
variable and it cannot be used as a variable.

7. The for loop is used to iterate over the elements of a sequence, whereas a while loop
executes a block of statements as long as the given condition is true.

8. A list is an ordered collection of items. It is written as a list of comma-separated values


(items) enclosed between square brackets. The syntax to create a list is: a = [10, 89, 56, 24,
67, 54]
9. a. append(): It is used to add a single item to the end of the list.

b. sort(): It sorts all the elements in the ascending order.

c. len(): It is used to find the total number of elements in the list

d. pop(): It is used to remove the last element from the list.

e. max(): It is used to returns the maximum or largest value in the list.

10. In the negative indexing, the last element in the list has index value of −1 and then the
index value keeps on decreasing with every next element. For example, in the list given
below:

L1=[10, 11, 12, 13, 14,15]

The corresponding index values are

Index values −6 −5 −4 −3 −2 −1

……………………………………………………………………………………………………………………………

You might also like