[go: up one dir, main page]

0% found this document useful (0 votes)
20 views13 pages

Data Handle Cls 11

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)
20 views13 pages

Data Handle Cls 11

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
You are on page 1/ 13

 Which of the following are valid Python data types?

 (a) Numeric

 (b) None

 (c) Mappings

 (d) List

 (e) Sequence

 (f) Set

 (g) Tuple

 (h) Dictionary

 Which of the following are datatypes considered as Numbers in Python?

 (a) Integer

 (b) Boolean

 (c) Complex

 (d) Floating point

 (e) List

 (f) None

 Consider the following sequence of statements:

python

Copy code

a = 35

b = 35

Following the execution of these statements, Python has created how many objects and how many
references?

 (a) Two integer objects, two references

 (b) Two integer objects, one reference

 (c) One integer object, two references

 (d) One integer object, one reference

 Which Python built-in function returns the unique number assigned to an object?

 (a) identity()

 (b) id()

 (c) refnum()
 (d) ref()

 The _____ operator is used to check if both the operands reference the same object memory.

 (a) in

 (b) is

 (c) id

 (d) are

 For two objects x and y, the expression x is y will yield True if and only if:

 (a) id(x) == id(y)

 (b) len(x) == len(y)

 (c) x == y

 (d) All of these

 Which of the following is not an immutable type in Python?

 (a) String

 (b) Tuples

 (c) Set

 (d) Dictionary

 What is the value of the expression 100 / 25?

 (a) 4.0

 (b) 4

 (c) none of these

 (d) 0.4

 What is the value of the expression 100 // 25?

 (a) 4

 (b) 4.0

 (c) none of these

 (d) 0.4

 In Python, a variable must be declared before it is assigned a value.

 (a) True

 (b) False

 _____ (a) Only in functions (b) Only in modules (c) Only in a variable is assigned a value of one
type, and then it is assigned a value of a different type. This will trigger a _____:
 (d) Warning

 (e) Error

 In Python, once assigned a value of one type, a variable can change to a different type. This
concept is known as _____:

 (a) mutability

 (b) static typing

 (c) dynamic typing

 (d) immutability

 Is it safe to add objects of type float and integer into another type?

 (a) Yes, if the values are <100

 (b) Yes, if the values are >100

 (c) No

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

20. What is the value of the expression 10 + 3 ** 3 + 27?

o (a) 28

o (b) 739

o (c) 829

o (d) 64

21. To increase the value of x five times using an assignment operator, the correct expression will
be:

o (a) x = x * 5

o (b) x *= 5

o (c) x **= 5

o (d) None of these

22. What will be the result of the expression 10 or 0?

o (a) 10

o (b) 1

o (c) 10 (in float)

o (d) 1.0

23. The result of the expression 5 or 10?

o (a) 5
o (b) 1

o (c) 10 (in float)

o (d) 10

24. The result of the expression 5 and 10 or 0?

o (a) 5

o (b) 1

o (c) 10

o (d) 0

25. The result of the expression 15 and 10 or 2?

o (a) 5

o (b) 1

o (c) 10

o (d) 2

26. The result of the expression 'a' or "" ("" is an empty string)?

o (a) 'a'

o (b) ""

o (c) 1

o (d) 0

27. The result of the expression 'a' and ""?

o (a) 'a'

o (b) ""

o (c) 1

o (d) 0

28. The result of the expression 'a' and 'a'?

o (a) 'a'

o (b) ""

o (c) 'x' and 'a'

o (d) 1

29. The result of the expression 'a' and 'x'?

o (a) 'a'

o (b) ""
o (c) 'x' and 'x'

o (d) 'x'

30. The result of the expression 'a' and 'None'?

o (a) 'a'

o (b) ""

o (c) 'None'

o (d) 1

31. The result of the expression None and 'a'?

o (a) 'a'

o (b) ""

o (c) 'None'

o (d) 1

32. The result of the expression False and False?

o (a) false

o (b) False

o (c) 'false'

o (d) 'False'

33. The result of the expression False or False?

o (a) false

o (b) False

o (c) 'false'

o (d) 'False'

Fill in the Blanks

1. Boolean data type is internally treated as a _____ data type.

2. Two forms of floating-point numbers are _____ form and _____ notation.

3. Python’s floating-point numbers have precision of _____ digits.

4. Three mutable types of Python are _____, _____, and _____.

5. The floor division of two integers yields a result of _____ type.

6. The division of two integers yields a result of _____ type.

7. The _____ sequence type cannot store duplicate values.

8. The _____ datatype is like lists but is not mutable.


9. The _____ of an object gives the memory location of the object.

10. To check if two objects reference the same memory address, _____ operator is used.

True/False Questions

1. List is an immutable data type.

2. Set is a mutable data type.

3. A Set can contain duplicate values in it.

4. A Boolean value is internally treated as an integer value.

5. "" (an empty string) has truth value as False.

6. ' ' (a space) has truth value as False.

7. Value False is a legal literal value in Python.

8. Value True is a legal literal value in Python.

9. Value 'False' is a legal literal value in Python.

10. None and "None" are the same.

11. None has the truth value as False.

12. The result of bool(0) is False.

13. The result of bool("None") is False.

14. Dividing two integers results in an integer.

15. Floor division of two integers results in an integer.

16. Two floating-point numbers should not be compared for equality using ==.

17. In implicit conversion, all operands’ data types are converted to the datatype of the largest
operand.

18. Explicit type conversion involves the use of a function to convert datatype of a value.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Assertions and Reasons


In the following questions, a statement of assertion (A) is followed by a statement of reason
(R). Choose the correct option:
 (a) Both A and R are true, and R is the correct explanation of A.
 (b) Both A and R are true, but R is not the correct explanation of A.
 (c) A is true, but R is false (or partly true).
 (d) A is false (or partly true), but R is true.
 (e) Both A and R are false (or not fully true).
1. Assertion: Mutability means that the values can be changed in place.
o Reason: Immutable types mean that their values cannot be changed in place.
2. Assertion: For evaluating a mixed type expression, Python carries out implicit type
conversion.
o Reason: In implicit type conversion, all operands are converted up to the type of the
largest operand.
3. Assertion: Type conversion can be implicit or explicit.
o Reason: Only Python interpreter can force the type conversion and not the
programmer.
4. Assertion: Syntax errors are the violations of grammatical rules of a programming language.
o Reason: The syntax errors can only be checked by the Python interpreter.
5. Assertion: The logical errors are the mistakes in analysis of a problem.
o Reason: Logical errors are the violations of syntax.
6. Assertion: The runtime errors occur during the execution of a program.
o Reason: The runtime errors may occur due to the unavailability of a resource
required for the program execution.
7. Assertion: Exceptions may occur even if a program is free from all types of errors.
o Reason: Irregular or unexpected situations arise during runtime which are outside
the programmer’s control.
Solved Problems
1. What are data types? What are Python's built-in core data types?
o Solution: To represent various types of real-life data, programming languages
provide ways and facilities to handle these, which are known as data types.
o Python’s built-in core data types belong to:
 Numbers (integer, floating-point, complex numbers, Booleans)
 String
 List
 Tuple
 Dictionary
2. Which data types of Python handle Numbers?
o Solution: Python provides the following data types to handle numbers:
 (i) Integers
 (ii) Booleans
 (iii) Floating-point numbers
 (iv) Complex numbers
3. Why is Boolean considered a subtype of integers?
o Solution: Boolean values 1 and 0 are treated internally as integers 1 and 0, i.e., True
and False are associated with integer values 1 and 0 respectively. When 1 and 0 are
converted, they evaluate as True and False.
4. Identify the data types of the values given below:
o Values: 3, 13.0, "13", 13, "13", 2+0j, 3, (3, 13), [3, 13]
o Solution:
 3 → integer
 13.0 → Floating-point
 "13" → String
 13 → integer
 "13" → String
 2+0j → complex
 (3, 13) → Tuple
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 What do you understand by the term 'immutable'?

 Solution: Immutable means unchangeable. In Python, immutable types are those whose
values cannot be changed in place. Whenever one assigns a new value to a variable referring
to an immutable type, the variable's reference is changed, and the previous value is left
unchanged. For example:

python

Copy code

x=3

x=5

o Here, the value 3 is untouched, and x is made to refer to a new value 5.

 What will be the output of the following?

python

Copy code

print(len(str(17//4)))

print(len(str(17/4)))

 Solution:

o The first line outputs 1 because:

python

Copy code

len(str(17//4)) = len(str(4)) = len("4") = 1

o The second line outputs 3 because:

python

Copy code

len(str(17/4)) = len(str(4.0)) = len("4.0") = 3

 What will be the output produced by these?

 (a) 12/4

 (b) 14/14

 (c) 14%4

 (d) 14/0.4
 (e) 14//0.4

 (f) 14.0%4

 Solution: The correct answer is:

o (a) 3.0

o (b) 1

o (c) 2

o (d) 3.5

o (e) 30.0

o (f) 2.0

 Given that variable CK is bound to string "Raman" (i.e., CK = "Raman"), what will be the output
produced by the following two statements if the input given is "Raman"? Why?

python

Copy code

DK = input("Enter name: ")

 (a) DK == CK

 (b) DK is CK

 Solution:

o The output produced will be:

 (a) True

 (b) False

o Explanation: The reason is that both DK and CK variables are bound to identical
strings, "Raman". However, input strings are always bound to fresh memory even if
they have identical content to other existing strings in memory. Therefore:

 DK == CK produces True as the strings are identical.

 DK is CK produces False as they are bound to different memory addresses.

 What will be the output of the following code? Explain the reason behind the output of every
line:

python

Copy code

5 < 5 or 10

5 < 10 or 5

5 < (10 or 5)
5 < (5 or 10)

 Solution:

o Output:

 10

 True

 True

 False

o Explanation:

 5 < 5 or 10 evaluates to False or 10, which returns 10.

 5 < 10 or 5 evaluates to True or 5, which returns True.

 5 < (10 or 5) evaluates to 5 < 10, which is True.

 5 < (5 or 10) evaluates to 5 < 5, which is False.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Program Correction

21. Problem: The program is giving a weird result of "0.50.50.50.50.50.50..........". Correct it so


that it gives the result in which the probability value (input as 0.5) times 150.

 Solution:

python

Copy code

probability = float(input("Type a number between 0 and 1: "))

print("Out of 150 tries, the odds are that only", int(probability * 150), "will succeed.")

 Hint: Ensure the correct datatype for probability.

Type C: Programming Practice/Knowledge-Based Questions

1. Write a program to obtain the principal amount, rate of interest, and time from the user
and compute simple interest.

2. Write a program to obtain temperatures of 7 days (Monday, Tuesday, ... Sunday) and then
display the average temperature of the week.

3. Write a program to obtain x, y, z from the user and calculate the expression:
4x4+3y3+9z+6π4x^4 + 3y^3 + 9z + 6\pi4x4+3y3+9z+6π.

4. Write a program that reads a number of seconds and prints it in the format: minutes and
seconds.
o Hint: Use // and % to get minutes and seconds. For example, 200 seconds are
printed as 3 mins and 20 seconds.

5. Write a program to take a year as input and check if it is a leap year or not.

6. Write a program to take two numbers and print if the first number is fully divisible by the
second number or not.

7. Write a program to take a 2-digit number and then print the reverse number.

o For example, if the input is 25, the program should print 52.

8. Try writing a program (similar to the previous one) for three-digit numbers.

o For example, if the input is 123, the program should print 321.

9. Write a program to take two inputs for day, month, and then calculate which day of the
year the date is.

o For simplicity, take 30 days for all months. For example, if you input 3 (March) and 3,
then it should print "Day of the year: 33".

10. Write a program that inputs an age and prints age after 10 years as shown.

o Example Output:

csharp

Copy code

What is your age? 17

In ten years, you will be 27 years old!

11. Write a program that asks a user for a number of years, and then prints out the number of
days, hours, minutes, and seconds in that number of years.

o Example Output:

yaml

Copy code

How many years? 1

10.0 years is :

3650.0 days

87600.0 hours

5256000.0 minutes

315360000.0 seconds

12. Write a program to find a side of a right-angled triangle whose sides and an angle are
given.
13. Write a program to calculate the radius of a sphere whose surface area 4πr24\pi r^24πr2 is
given.

14. Write a program that inputs a string and then prints it equal to its length.

o Example:

vbnet

Copy code

Enter string: "eka"

Result: ekaekaeka

15. Find the volume of a cylinder (πr2h\pi r^2 hπr2h) as shown on the right.

16. Write a program to input the radius of a sphere and calculate its volume V=43πr3V = \
frac{4}{3} \pi r^3V=34πr3.

17. Write a program to calculate the amount payable after simple interest

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

You might also like