IC208 - Programming for Finance Seminar 2
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
IC208 - Programming for Finance
Seminar 2 – Solutions
Q1) What is the output of following code?
print (2**3)
a) 6
b) an error message
c) 2**3
d) 8
Ans: d
Q2) What is the output of following code?
print (9/3)
a) 3
b) 9/3
c) 3.0
d) 3.00
Ans: c
Q3) What is the output of following code?
print (10//3)
a) 3
b) 3.33
c) 3.0
d) 1
Ans: a
Q4) What is the output of following code?
print (10%3)
a) 3
b) 3.33
c) 3.0
d) 1
Ans: d
Q5) What is the output when following code is executed?
print ("a"+"bc")
e) a
f) bc
g) bca
h) abc
Ans: d - + operator is a concatenation operator
Q6) What is the output when following statement is executed?
print ("3"*5)
a) 33333
b) 35
c) an error message
d) 3*5
Ans: a - * is used to multiply strings
Q7) What arithmetic operators cannot be used with strings?
a) +
b) *
c) –
d) All of the mentioned
Ans: c - + is used to concatenate and * is used to multiply strings
Q8) What is the output when following code is executed?
str1 = 'hello'
print (str1[- 1:])
a) olleh
b) hello
c) h
d) o
Ans: d - - 1 corresponds to the last index and : is the slice operator for strings
Q9) What is the output when following code is executed?
str1="helloworld"
print (str1[::- 1])
a) dlrowolleh
b) hello
c) world
d) helloworld
Ans: a – Execute in Spyder and verify, the code in the print statement reverses the letters in the string
Q10) Write a program to define a variable: mylist = [1, 4, 7], and then add the number: 9 to the
list before printing it.
Solution:
mylist = [1, 4, 7]
mylist.append(9)
print (mylist)
Q11) What is the output when following code is executed?
a = 7
if a >5:
print(“five”)
if a >8:
print(“eight”)
Answer:
“five”
Q12) What is the output when following code is executed?
mylist = [1,2,3,4,5,6,7]
for x in mylist:
if (x%2==1) and (x>4):
print(x)
break
Answer:
5
Q13) What is the output when following code is executed?
mylist = [1,2,3,4,5,6,7]
for x in mylist:
if (x%2==1) and (x>4):
print(x)
continue
Answer:
5
7
2023-03-06