Sunday, 4 August 2019

Assessment 5

Assessment 5


1. What is the syntax of the following piece of code?
>>> a=frozenset(set([5,6,7]))
>>> a
a) {5,6,7}
b) frozenset({5,6,7})
c) frozen ({5,6,7})
d) frozenset(set{5,6,7})
Ans: B

2. What is the output of the following code?
>>> a={1,2,3}
>>> b=frozenset([3,4,5])
>>> a-b
a) {1,2}
b) {1,2,4,5}
c) {4,5}
d) {12}
Ans: A

3. Create 10 phone numbers with names and display it.
Ans:
>>> d={8980:"raj",43424:"ravi"}
>>> d
{8980: 'raj', 43424: 'ravi'}

4. Write a Python script to merge two Python dictionaries.
d1 = {'a': 100, 'b': 200}
d2 = {'x': 300, 'y': 200}

Ans:
d1 = {'a': 100, 'b': 200}
d2 = {'x': 300, 'y': 200}
d = d1.copy()
d.update(d2)
print(d)

5. Evaluate the following expression
>>> b=4+5-2*5/2
>>>
Ans: 4.0

6. Write a Python program to add a key to a dictionary ex:(2:30).
d = {0:10, 1:20}
Ans:
d = {0:10, 1:20}
print(d)
d.update({2:30})
print(d)

7. Which of these about a frozenset is not true?
a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type
Ans: A

8. Write a logic to Display the following output:
              2
              6
             10
             14
             18

Ans:
>>> a=range(2,20,4)
>>> for i in a:print(i)

9. What is the output: a=bytes([10,'sita',True,2+3j]

Ans: Error

10. What is the operators? How many types of operators in python?
Ans:

An operator is a symbol which is used to perform an operation on operands (values and variables).Types of operators:
1.  Arithmetic
2.  Assignment
3.  Relational operators
4.  Logical operator
5.  Boolean operator
6.  Bitwise operator
7.  Membership
8.  Identity operators

Youtube channel click here to see this video
Next Topic: Operators
Assessment 6
Previous Assessment: Assessment 4

You may like the following posts:


No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(...