Data Handle Cls 11
Data Handle Cls 11
(a) Numeric
(b) None
(c) Mappings
(d) List
(e) Sequence
(f) Set
(g) Tuple
(h) Dictionary
(a) Integer
(b) Boolean
(c) Complex
(e) List
(f) None
python
Copy code
a = 35
b = 35
Following the execution of these statements, Python has created how many objects and how many
references?
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:
(c) x == y
(a) String
(b) Tuples
(c) Set
(d) Dictionary
(a) 4.0
(b) 4
(d) 0.4
(a) 4
(b) 4.0
(d) 0.4
(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
(d) immutability
Is it safe to add objects of type float and integer into another type?
(c) No
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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 (a) 10
o (b) 1
o (d) 1.0
o (a) 5
o (b) 1
o (d) 10
o (a) 5
o (b) 1
o (c) 10
o (d) 0
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
o (a) 'a'
o (b) ""
o (c) 1
o (d) 0
o (a) 'a'
o (b) ""
o (d) 1
o (a) 'a'
o (b) ""
o (c) 'x' and 'x'
o (d) 'x'
o (a) 'a'
o (b) ""
o (c) 'None'
o (d) 1
o (a) 'a'
o (b) ""
o (c) 'None'
o (d) 1
o (a) false
o (b) False
o (c) 'false'
o (d) 'False'
o (a) false
o (b) False
o (c) 'false'
o (d) 'False'
2. Two forms of floating-point numbers are _____ form and _____ notation.
10. To check if two objects reference the same memory address, _____ operator is used.
True/False Questions
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.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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
python
Copy code
print(len(str(17//4)))
print(len(str(17/4)))
Solution:
python
Copy code
python
Copy code
(a) 12/4
(b) 14/14
(c) 14%4
(d) 14/0.4
(e) 14//0.4
(f) 14.0%4
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
(a) DK == CK
(b) DK is CK
Solution:
(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:
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:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Program Correction
Solution:
python
Copy code
print("Out of 150 tries, the odds are that only", int(probability * 150), "will succeed.")
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
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
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
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
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::