Вы находитесь на странице: 1из 10

K S R INSTITUTE FOR ENGINEERING AND TECHNOLOGY

Department of Computer Science and Engineering & Department of Information


Technology

Placement Training on Python Programming 2020-2021

Assessment Questions

Day 1

1. Assignment

Print a Statement "Hello World"

2. Quiz

1. In Python, what is one function to output content to the console?

 echo
 output
 print
 console.log

2. Which of the following statements is NOT true about Python?

 Python’s syntax is much like PHP


 Python can be used for web development
 Python can run on any type of platform
 Python can be used to generate dynamic web pages

3. What symbol can you use to comment out one line of code?

 *
 (comment)
 //
 #

4. How do you create a variable "a" that is equal to 2?

 var a = 2
 int a = 2
 a=2
 variable a = 2
5. How would you cast the string variable "a" that is equal to "2" into the integer 2?

 castToInt(a)
 int(a)
 integer(a)
 castToInteger(a)

6. How would you cast the int variable "a" that is equal to 2 into the string "2"?

 int(a)
 castToString(a)
 str(a)
 string(a)

7. What is the output of this Python program?

x = 17 / 2 % 2 * 3 ** 3

print (x)

 0
 16
 54.0
 None

8. The following program will create the output shown beneath it.

Program:

print (7 > 10)

print (4 < 16)

print (4 == 4)

print (4 <= 4)

print (4 != 4)

Output:

False

True
True

True

False

 True
 False

Day 2

1. Assignment

Write a program by declaring 10 variables and use all the mathematical


Operations?

2. Quiz

1. What is the data type of a value such as 3.142?

 float
 string
 int
 Boolean

2. What is the data type of a value such as 3?

 float
 string
 int
 Boolean

3. What is the data type of a value such as "anne was here"?

 float
 string
 int
 Boolean

4. The following Python code results in

s = "Hello there"

a = s.islower()
b = s.lower()

 a is the Boolean False and b is the string “hello there”


 a is the Boolean True
 a is the string “hello there”
 b is the Boolean False

5. How can you replace all of the letter a in a string variable "example" with the letter b?

 example.swap(‘b’,’a’)
 example.replace(‘a’,’b’)
 example.match(‘b’,’a’)
 example.replace(‘b’,’a’)

Day 3

1. Assignment

Get the age of the user through input and print whether the age is eligible for voting
or not, if the age is 20 print eligible else print not eligible.

2. Quiz

1. The following Python code results in

def f(n):

return n*n

a = f(2)

 A function “f” is defined


 A integer “f” is defined
 A variable ‘a’ is assigned the value of 4
 Both A & C

2. Which one of the following is a valid Python if statement

 If a >= 22:
 If (a >= 22)
 If (a => 22)
 If a >= 22
3. What keyword would you use to add an alternative condition to an if statement?

 else if
 elseif
 elif
 None of the above

4. Which of the following is a valid way to start a function in Python?

 def someFunction():
 function someFunction()
 def someFunction()
 function someFunction():

5. How to find the length of the string ?

print('word'[-1])

 length()
 size()
 char()
 len()

6. How do you call the declared function?

 Function_name.call()
 Function_name()
 Function_name.invoke()
 Function_name.process()

7. If you have a variable "example", how do you check to see what type of variable you are
working with?

 getType(example)
 Type(example)
 type(example)
 example.type

8. What is the output of this Python program?

num1 = 5

if num1 >= 91:


num2 = 3

else:

if num1 < 6:

num2 = 4

else:

num2 = 2

x = num2 * num1 + 1

print (x,x%7)

 21 3
 21 0
 21 21
 None of the above

9. The three types of error that might be contained in a Python program are syntax, logic
and run-time.

 True
 False

Day 4

1. Assignment

Write a function that takes an exploder function and N. the exploder function explodes the
given string into N times

Function Prototype:

Exploder(string,n)

Myfun(string,exploder,n)

Input: CSE 5

Output: CSECSECSECSECSE
2. Quiz

1. Which of the following is a valid list in Python?

 sampleList = {1,2,3,4,5}
 sampleList = (1,2,3,4,5)
 sampleList = /1,2,3,4,5/
 sampleList = [1,2,3,4,5]

2. Which of the following is a valid tuple in Python?

 sampleTuple = {1,2,3,4,5}
 sampleTuple = (1,2,3,4,5)
 sampleTuple = /1,2,3,4,5/
 sampleTuple = [1,2,3,4,5]

3. Which of the following is a valid dictionary in Python?

 myExample = {‘someItem’=>2, ‘otherItem’=>20}


 myExample = {‘someItem’:2, ‘otherItem’:20}
 myExample = (‘someItem’=>2, ‘otherItem’=>20)
 myExample = (‘someItem’:2, ‘otherItem’:20)

4. What is the output when the following code is executed?

list1=[2,4,6,8,10,12,14,16,18,20]
print (list1[0:1],list1[5:7])

 [2,4][10,12]
 [2,4][12,14]
 [2][12,14]
 [2][10,12,14]

5. How would you print the second item in the list variable "example"?

 print(example[2])
 echo(example[2])
 print(example[1])
 print(example(2))
6. What would the statement "print('%.2f' % 123.444)" print out?

 123.44
 12
 123.440
 44

Day 5

1. Assignment

Read a integer in a file e.g 123 and convert it to words e.g One hundred and twenty
three and write back to same file

2. Quiz

1. What is the keyword used after the try statement to handle exceptions?

 catch
 exception
 catch(a)
 except

2. What is the proper way to open a file that you intend to read from?

 f = open(“test.txt”,”read”)
 f = open(“r”,”test.txt”)
 f = open(“test.txt”,”r”)
 f = open(“read”,”test.txt”)

3. What is the proper way to open a file that you plan to write to?

 f = open(“test.txt”,”w”)
 f = open(“test.txt”,”write”)
 f = open(“write”,”test.txt”)
 f = open(“w”,”test.txt”)

4. What is the difference between a class and an object in Python?

 There is no difference between a class and an object


 Classes are made from iterations while objects are not
 Objects are not able to be called
 Objects are created from classes
Day 6

1. Assignment

Python Program to find largest element in an array

Day 7

1. Assignment

Get a list of name and make them title caps and print the list

Вам также может понравиться