[go: up one dir, main page]

0% found this document useful (0 votes)
213 views10 pages

Python Assignment Application Type

The document provides an assignment on Python programming with 54 multiple choice questions related to Python concepts like lists, dictionaries, functions, loops etc. It tests the understanding of basic Python syntax, data types, operators and built-in functions through code snippets and output questions.

Uploaded by

Adarsha M R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
213 views10 pages

Python Assignment Application Type

The document provides an assignment on Python programming with 54 multiple choice questions related to Python concepts like lists, dictionaries, functions, loops etc. It tests the understanding of basic Python syntax, data types, operators and built-in functions through code snippets and output questions.

Uploaded by

Adarsha M R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

|| JAI SRI GURUDEV ||

SJC INSTITUTE OF TECHNOLOGY, CHICKABALLAPUR


DEPARTMENT OF CIVIL ENGINEERING
SUBJECT: INTRODUCTION TO PYTHON PROGRAMMING
SUBJECT CODE: BPLCK105B
FACULTY INCHARGE: ADARSHA M R
SEMESTER & BRANCH: I SEM AIML

ASSIGNMENT (APPLICATION LEVEL)

STUDENT NAME: ____________________________________

USN: ________________________

1. What is the output of the following code?


var1 = 1
var2 = 2
var3 = "3"
print(var1 + var2 + var3)
A. 6
B. 33
C. 123
D. Error. Mixing operators between numbers and strings are not supported

2. What is the output of the following


x = 36 / 4 * (3 + 2) * 4 + 2
print(x)
A. 182.0
B. 37
C. 117
D. The Program executed with errors

3. A string is immutable in Python? Every time when we modify the string, Python
Always create a new String and assign a new string to that variable.
A. True
B. False

4. The in operator is used to check if a value exists within an iterable object


container such as a list. Evaluate to True if it finds a variable in the specified
sequence and False otherwise.
A. True
B. False

Page 1 of 10
5. What is the output of the following code?
var= "James Bond"
print(var[2::-1])
A. Jam
B. dno
C. maJ
D. dnoB semaJ

6. What is the output of the following code?


listOne = [20, 40, 60, 80]
listTwo = [20, 40, 60, 80]
print(listOne == listTwo)
print(listOne is listTwo)
A. True and True
B. True and False
C. False and True

7. Can we use the “else” block for for loop? For example:
for i in range(1, 5):
print(i)
else:
print("this is else block statement" )
A. No
B. Yes

8. What is the output of the following code?


p, q, r = 10, 20 ,30
print(p, q, r)
A. 10 20
B. 10 20 30
C. Error: invalid syntax

9. What is the output of the following code?


var = "James" * 2 * 3
print(var)
A. JamesJamesJamesJamesJamesJames
B. JamesJamesJamesJamesJames
C. Error: invalid syntax

10. What is the Output of the following code?


for x in range(0.5, 5.5, 0.5):
print(x)
A. [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5]
B. [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
C. The Program executed with errors
Page 2 of 10
11. Which operator has higher precedence in the following list
A. % (Modulus)
B. & (BitWise AND)
C. ** (Exponent)
D. > (Comparison)

12. What is the output of the following code?


sampleSet = {"Jodi", "Eric", "Garry"}
sampleSet.add(1, "Vicki")
print(sampleSet)
A. {‘Vicki’, ‘Jodi’, ‘Garry’, ‘Eric’}
B. {‘Jodi’, ‘Vicki’, ‘Garry’, ‘Eric’}
C. The program executed with error

13. What is the output of the following code?


str = "pynative"
print (str[1:3])
A. py
B. yn
C. pyn
D. yna

14. What is the output of the following code?


for i in range(10, 15, 1):
print( i, end=', ')
A. 10, 11, 12, 13, 14,
B. 10, 11, 12, 13, 14, 15,

15. What is the output of the following code?


sampleList = ["Jon", "Kelly", "Jessa"]
sampleList.append(2, "Scott")
print(sampleList)
A. The program executed with errors
B. [‘Jon’, ‘Kelly’, ‘Scott’, ‘Jessa’]
C. [‘Jon’, ‘Kelly’, ‘Jessa’, ‘Scott’]
D. [‘Jon’, ‘Scott’, ‘Kelly’, ‘Jessa’]

16. What is the output of the following code?


def calculate (num1, num2=4):
res = num1 * num2
print(res)
calculate(5, 6)
A. 20
B. The program executed with errors
C. 30
Page 3 of 10
17. What is the output of the following code?
valueOne = 5 ** 2
valueTwo = 5 ** 3
print(valueOne)
print(valueTwo)
A. 10 and 15
B. 25 and 125
C. Error: invalid syntax

18. What is the output of the following code


salary = 8000
def printSalary():
salary = 12000
print("Salary:", salary)
printSalary()
print("Salary:", salary)
A. Salary: 12000 Salary: 8000
B. Salary: 8000 Salary: 12000
C. The program failed with errors

19. What is the data type of the following


aTuple = (1, 'Jhon', 1+3j)
print(type(aTuple[2:3]))
A. list
B. complex
C. tuple

20. What is the output of the following code


print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
A. False True False True
B. True True False True
C. True True False True
D. False True True True

21. What is the output of the following code?


x = 50
def fun1( ):
x = 25
print(x)
fun1( )
print(x)
A. NameError
B. 25 and 25
C. 25 and 50

Page 4 of 10
22. Select all the right ways to create a string literal Ault'Kelly
A. str1 = 'Ault\\'Kelly'
B. str1 = 'Ault\'Kelly'
C. str1 = """Ault'Kelly"""

23. In Python 3, what is the output of type(range(5)). (What data type it will return).
A. int
B. list
C. range
D. None

24. Select all the valid String creation in Python


A. str1 = 'str1'
str1 = "str1"
str1 = '''str'''
B. str1 = 'str1'
str1 = "str1""
str1 = '''str1''
C. str1 = str(Jessa)

25. Please select the correct expression to reassign a global variable “x” to 20 inside a
function fun1()
x = 50
def fun1():
# your code to assign global x = 20
fun1()
print(x) # it should print 20
A. global x =20
B. global var x
x = 20
C. global.x = 20
D. global x
x = 20

26. What is the data type of print(type(10))


A. float
B. integer
C. int

27. What is the data type of print(type(0xFF))


A. number
B. hexint
C. hex
D. int

Page 5 of 10
28. What is the result of print(type([]) is list)
A. False
B. True

29. What is the output of the following code


def func1():
x = 50
return x
func1()
print(x)
A. 50
B. NameError
C. None
D. 0

30. What is the output of the following variable assignment?


x = 75
def myfunc():
x=x+1
print(x)
myfunc()
print(x)
A. Error
B. 76
C. 1
D. None

31. What is the output of print(type({}) is set)


A. True
B. False

32. What is the output of the following list assignment


aList = [4, 8, 12, 16]
aList[1:4] = [20, 24, 28]
print(aList)
A. [4, 20, 24, 28, 8, 12, 16]
B. [4, 20, 24, 28]

33. What is the output of the following list comprehension


resList = [x+y for x in ['Hello ', 'Good '] for y in ['Dear', 'Bye']]
print(resList)
A. [‘Hello Dear’, ‘Hello Bye’, ‘Good Dear’, ‘Good Bye’]
B. [‘Hello Dear’, ‘Good Dear’, ‘Hello Bye’, ‘Good Bye’]

Page 6 of 10
34. What is the output of the following list operation
sampleList = [10, 20, 30, 40, 50]
print(sampleList[-2])
print(sampleList[-4:-1])
A. 40
[20, 30, 40]
B. IndexError: list index out of range

35. What is the output of the following code?


sampleList = [10, 20, 30, 40]
del sampleList[0:6]
print(sampleList)
A. []
B. list index out of range.
C. [10, 20]

36. What is the output of the following list function?


sampleList = [10, 20, 30, 40, 50]
sampleList.append(60)
print(sampleList)
sampleList.append(60)
print(sampleList)
A. [10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60]
B. [10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60, 60]

37. What is the output of the following list operation


aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
A. [20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
B. [30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]

38. What is the output of the following


l = [None] * 10
print(len(l))
A. 10
B. 0
C. Syntax Error
Page 7 of 10
39. Select all the correct options to join two lists in Python
listOne = ['a', 'b', 'c', 'd']
listTwo = ['e', 'f', 'g']
A. newList = listOne + listTwo
B. newList = extend(listOne, listTwo)
C. newList = listOne.extend(listTwo)
D. newList.extend(listOne, listTwo)

40. In Python, list is mutable


A. False
B. True

41. What is the output of the following code


aList = ["PYnative", [4, 8, 12, 16]]
print(aList[0][1])
print(aList[1][3])
A. P 8
Y 16
B. P
12
C. Y
16

42. What is the output of the following


aList = [5, 10, 15, 25]
print(aList[::-2])
A. [15, 10, 5]
B. [10, 5]
C. [25, 10]

43. What is the output of the following


aList = [1, 2, 3, 4, 5, 6, 7]
pow2 = [2 * x for x in aList]
print(pow2)
[2, 4, 6, 8, 10, 12, 14]
[2, 4, 8, 16, 32, 64, 128]

44. What is the output of the following code


my_list = ["Hello", "Python"]
print("-".join(my_list))
A. HelloPython-
B. Hello-Python
C. -HelloPython

Page 8 of 10
45. Dictionary keys must be immutable
A. True
B. False

46. In Python, Dictionaries are immutable


A. False
B. True

47. Select correct ways to create an empty dictionary


A. sampleDict = {}
B. sampleDict = dict()
C. sampleDict = dict{}

48. Select the correct ways to get the value of marks key.
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
A. m = student.get(2)
B. m = student.get('marks')
C. m = student[2])
D. m = student['marks'])

49. What is the output of the following code


dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
A. True
B. False

50. Items are accessed by their position in a dictionary and All the keys in a dictionary
must be of the same type.
A. True
B. False

51. Select the correct way to print Emma’s age.


student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'},
2: {'name': 'Mike', 'age': '22', 'sex': 'Male'}}
A. student[0][1]
B. student[1]["age"]
C. student[0]["age"]

Page 9 of 10
52. What is the output of the following
sampleDict = dict([
('first', 1),
('second', 2),
('third', 3)
])
print(sampleDict)
A. [ (‘first’, 100), (‘second’, 200), (‘third’, 300) ]
B. SyntaxError: invalid syntax
C. {‘first’: 1, ‘second’: 2, ‘third’: 3}

53. What is the output of the following dictionary operation


dict1 = {"name": "Mike", "salary": 8000}
temp = dict1.get("age")
print(temp)
A. KeyError: ‘age’
B. None

54. Write a program that determines whether a given word or number or phrase is a
palindrome. Palindrome means it reads the same both forward and backward. Eg:
121121, MALAYALAM
55. Create a basic calculator for addition, subtraction, multiplication and division
arithmetic operations. Scientific features like square root and exponentiation have
to be included.

Page 10 of 10

You might also like