Which data type will be used to represent the following data values and why?


a) Number of months in a year.
b) Resident of Delhi or not
c) Mobile number
d) Pocket money
e) Volume of a sphere
f) Perimeter of a square
g) Name of the student
h) Address of the student

ANS:

a) ‘int’ data type will be used because number of months is always an integer or whole number.

b) ‘bool’ (boolean) data type is used because Resident of Delhi is represented either in True (yes) or False (no). 

c) ‘string’ data type will be used. Although Mobile no is number but is taken as string because it is often used for ID not for calculation.

d) ‘int’ data type will be used because pocket money is always an integer value.

e) ‘float’ data type will be used because volume of sphere can be a floating number or value with decimal point.

f) ‘float’ data type will be used because Perimeter of a square can be a floating number or value with decimal point.

g) ‘string’ data type will be used because Name of the student is always a string or text.

h) ‘string’ data type will be used because Address of the student can have alphanumeric values which are taken as string.

error: Content is protected !!