0% found this document useful (0 votes)
57 views2 pages

CP II Midterm 2022 Answers

The document is a midterm exam for a computer programming course consisting of 15 multiple choice and written response questions. The questions cover topics like Python string indexing and slicing, functions, loops, conditional statements, lists, and modules. The written questions involve writing code to split a string into a list, sort a list without using the built-in sort function, and take user input of numbers separated by spaces and store in a list.

Uploaded by

Özlem Altınok
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)
57 views2 pages

CP II Midterm 2022 Answers

The document is a midterm exam for a computer programming course consisting of 15 multiple choice and written response questions. The questions cover topics like Python string indexing and slicing, functions, loops, conditional statements, lists, and modules. The written questions involve writing code to split a string into a list, sort a list without using the built-in sort function, and take user input of numbers separated by spaces and store in a list.

Uploaded by

Özlem Altınok
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/ 2

Name/Lastname: April 29, 2022

Student Id:

Necmettin Erbakan University


Department of Industrial Engineering
INE108 Computer Programming I Course Midterm Exam
(Questions 1 to 12 are 5 points each, questions 13 is 10 points, questions 14 and 15 are 15 points)

1) str = "pynative"
print (str[2:4])
What is the output of the above code? 7) x=5
A) py B) yn C) na D) yna y="5"
if x=y:
2) var1 = "1" print("Equal")
var2 = "2" else:
var3 = "3" print("Not Equal")
print(var1+ var2 + var3) What is the output of the above code?
What is the output of the above code? A) Equal B) Not Equal C) Error
A) 6 B) 33 C)123 D) Error

3) def calculate (num1, num2=4): 8) To retrieve the first character “c” from string,
res = num1 * num2 mystr="codescracker" What command do we execute?
print(res) A) mystr[1] B) mystr.getItem(1) C) mystr[0]
calculate(5)
What is the output of the above code? 9) x=[1,2,3,4,5]
A) 20 B) 30 C) Error y=x
x.append(6)
4) def rev_func(x,length): print(y[5])
if length>0: What is the output of the above code?
print(x[length-1],end=" ") A) 5 B) 6 C) Error D)-1
rev_func(x,length-1)
x=[11, 12, 13, 14, 15] 10) tinylist = [123, 'john']
rev_func(x,5) print(tinylist *
What is the output of the above code? What is the output of the above code?
A)15 14 13 12 11 B) 11 12 13 14 A) [123, 'john', 123, 'john'] B) [123, 'john'] * 2
C) Error D) 11121314 C) [246, 'johnjohn'] * 2 D) Error

5) Which of the following statement causes the loop 11)


to skip the remainder of its body and immediately a = 330
retest its condition prior to reiterating? b = 331
print("A") if a > b else print(">") if a < b else print("B")
A) break B) continue C) pass D) None of them What is the output of the above code?
A) A B) > C) B
6) str = 'Hello World!'
print(str * 2)
What is the output of the above code? 12) ktinker module is used to create GUI for Python.
A) Hello World!Hello World! Evaluate the above statement:
B) Hello World! * 2 A) True B) False
C) Hello World!
D) Error
Name/Lastname: April 29, 2022
Student Id:

13) x=’1 2 3 45 47 48 49’


Write a code that separates the numbers in string 15) Write a code that is going to get some numbers
variable x and stores them in a list variable y. (10 separated by blank space from the user on screen and
Points) store them in a list variable named x. (15 points)
x='1 2 3 45 47 48 49'
y=str.split(x) x=input(“Enter the numbers: ”)
print(y) x=str.split(x)
print(x)

14) x= [3,5,6,12,44,33,22,55,4,67,112,68]
Write a code that is going to sort the numbers in list x
and display them. Do not use the built in sort function
of Python. (Hint: You can us for loops) (15 Points)
x= [3,5,6,12,44,33,22,55,4,67,112,68]

for i in range(len(x)):
index=i
current_min=x[index]
for k in range(i+1, len(x)):
if x[k]<x[index]:
index=k
temp=x[i]
x[i]=x[index]
x[index]=temp

print(x)

[3, 4, 5, 6, 12, 22, 33, 44, 55, 67, 68, 112]

You might also like