Page 169 - Computer Science Class 11 With Functions
P. 169
In the above example, the variable (name), x is accessed for printing its value before it is assigned a value. So, a
NameError is displayed because the name x is unknown to the interpreter. In the following example, the use of int
and str objects is incompatible with the + operator, so the interpreter points out a TypeError.
>>> 10 + "Hello"
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
10 + "Hello"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Match the following:
1. Implicit type conversion a. Infinite loop
2. Syntax Error b. Trying to read a file that does not exist
3. Logical Error c. y = int(input("Enter a number"))
4. Explicit Type conversion d. PRINT()
5. Runtime Error e. coercion
Common Errors
● Missing quotation marks for strings
print(India) # string value not enclosed in quotation marks
● Not using the same quotation marks before and at the end of the string
print("India')
print('India")
# the string not enclosed within same type of quotation marks
● Copying a string from a word processor, For example,
>>> print(‘India’)
SyntaxError: invalid character ''' (U+2018)
Also, observe the following,
>>> ord("'")
39
>>> ord("’")
8217
>>> ord("‘")
8216
● Not using correct brackets for data types
myList = (1,2,5,9)
# The programmer wanted to create a list, but produced a tuple.
Let's Summarise
Ø A data type denotes a set of specific type of values. For example, the data type int includes negative and
non-negative integers.
Ø A numeric data type can store only numbers or numeric values on which arithmetic operations can be
performed.
Ø Numeric data type may be: int, float, and complex.
Ø bool or Boolean data type consists of two possible values: True and False.
Data Types and Operators 167

