Font size
WorksheetsIntro to Python by AUG Problem solving module
Total questions: 24
Worksheet time: 14mins
What symbol do you use to make a comment in one line in Python?
#
''
$
!
Which of the following is constructed by placing expressions within square brackets?
Lists
Classes
Tuples
sets
For strings, the + operator represents
Concatenation
Appending
Addition
Recantation
What is printed by the following statement?
print("P" not in "APCSP")
True
False
Error
str1="helloworld"
print(str1[ : :-1])
worldhello
hello
helloworld
dlrowolleh
>>>"abcd"[2:]
ab
a
cd
dc
>>>i = 2
>>>while True:
if i%3 == 0:
break
print(i)
i += 2
2 4
2 3
error
2 4 6 8 10 …
Q4.
What is the order of precedence in Python?
1. Subtraction
2. Exponential
3. Multiplication
4. Division
5. Addition
6. Parenthesis
Enter the numbers in the right order
(a)
Choose the correct syntax of the split function:
x.split[]
X.SPLIT(",", 3)
x.split(",", 3)
split(x)
The code above prints all numbers between 1 and 30 that are
not divisible by 5
divisible by 5
The program above prints the sum of all the numbers between 0 and 101 that are
alternate odd numbers
alternate even numbers
alternate numbers
How many times will 1 be printed
3
4
5
6
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
What is the output of the program above ?
b is bigger
a is bigger
Syntax error : tuples can't be compared
The code above prints
Math
Physics
Chemistry
English
4
3.8
3.6
3.7
None
None
None
None
NaN
NaN
NaN
NaN
Select all the correct options to copy a list
aList = ['a', 'b', 'c', 'd']
newList = copy(aList)
newList = aList.copy()
newList.copy(aList)
newList = list(aList)
What would this code return on the shell?
Nothing
An error
"Woo hoo, you scored!"
"Raheem"
Suppose list1 is [1, 5, 9], what is sum(list1) ?
1
9
15
none
Which of the following commands will return the length of the list mylist?
length(mylist)
len(mylist)
mylist.length()
mylist.len()
What is the output of program below?
motorcycles = ['honda', 'yamaha', 'suzuki']
motorcycles.sort()
print(motorcycles)
['honda', 'yamaha', 'suzuki']
['yamaha', 'suzuki', 'honda']
['honda', 'suzuki', 'yamaha']
['suzuki', 'yamaha', 'honda']
print("abcdef".find("cd"))
2
3
Error
True
print("Hello {} and {}".format('foo', 'bin'))
Hello {} and {}
Hello and
Hello {}
Hello foo and bin
What will be the output of the following Python code snippet?
x = [i**+1 for i in range(3)]; print(x);
[0, 1, 2]
error, ‘;’ is not allowed
error, **+ is not a valid operator
[1, 2, 5]
