Python for Data Science
Unit 4 – Week 1
Assignment Questions
1. Which of the following variable names are INVALID in Python?
a) 1_variable
b) variable_1
c) variable1
d) variable#
2. Which of the following operators have lower precedence than not in Python?
a) +
b) and
c) ==
d) |
3. What will be the output of the following code?
a = 10 b = 5 print(a ** b % 3)
a) 0
b) 100
c) 1
d) 2
4. What will be the output of the following code snippet?
greetings = "Namaste" greetings_1 = float(greetings) print(type(greetings_1))
a) int
b) float
c) str
d) Code will throw an error
5. Given two variables j = 6 and g = 3.3. If both normal division and floor division operators are used
to divide j by g, what would be the data type of the values obtained?
a) float, float
b) float, int
c) int, float
d) int, int
6. What will be the output of the following code snippet?
a = "10" b = float(a) + 5 result = str(b) + "123" print(type(result))
a) <class 'float'>
b) <class 'str'>
c) <class 'int'>
d) The code will give an error
7. What will be the output of the following code snippet?
a = 15 b = 3 c = 4 result = a + b * c // (c % b) - 5 print(result)
a) 20
b) 1
c) 22
d) 0
8. What is the output of the following code snippet?
a = 4 b = 5 a *= b * 2 print(a)
a) 10
b) 20
c) 25
d) 40
9. What is the output of the following code snippet?
a = 3 b = 5 c = (a == 3) and (b == 5) or (a != 3) print(c)
a) True
b) False
c) Error
10. Let a = 5 (101 in binary) and b = 3 (011 in binary). What is the result of the following operation?
a = 5 b = 3 print(a & b)
a) 3
b) 7
c) 5
d) 1