Python Assessment
Python Assessment
Assessment Questions
Day 1
1. Assignment
2. Quiz
echo
output
print
console.log
3. What symbol can you use to comment out one line of code?
*
(comment)
//
#
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)
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 (4 == 4)
print (4 <= 4)
print (4 != 4)
Output:
False
True
True
True
False
True
False
Day 2
1. Assignment
2. Quiz
float
string
int
Boolean
float
string
int
Boolean
float
string
int
Boolean
s = "Hello there"
a = s.islower()
b = s.lower()
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
def f(n):
return n*n
a = f(2)
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
def someFunction():
function someFunction()
def someFunction()
function someFunction():
print('word'[-1])
length()
size()
char()
len()
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
num1 = 5
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
sampleList = {1,2,3,4,5}
sampleList = (1,2,3,4,5)
sampleList = /1,2,3,4,5/
sampleList = [1,2,3,4,5]
sampleTuple = {1,2,3,4,5}
sampleTuple = (1,2,3,4,5)
sampleTuple = /1,2,3,4,5/
sampleTuple = [1,2,3,4,5]
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”)
1. Assignment
Day 7
1. Assignment
Get a list of name and make them title caps and print the list