Font size
WorksheetsPython El Grand Revision!
Total questions: 47
Worksheet time: 49mins
We use "git (a) " command to upload the content of local repository to the remote repository
We use "git (a) " command to stage changes by adding new or modified files to the staging area
In order to update the content of the local repository with that from the remote repository, we use:
git push
git commit
git pull
git add
We want to build a program to accept a number, check if it's divisible by 7 and print suitable message. What would the main condition have to be?
if num %7 == 0:
if num %7 == 7:
if num ** 7:
if 7 == num:
To generate even numbers between 19 and 34 (inclusive) we would call:
range(19,34)
range(19,34,2)
range(19,35,2)
range(18,35,2)
Which of the following is NOT a valid way of importing functions/modules?
from tui import *
import * from tui
import func
from tui import func
Let x = ("pear", "apple", "orange", "raspberry")
What does print(x[-2]) achieve?
"orange" is printed on the console
Error is generated
"x[-2]" is printed on the console
"apple" is printed on the console
Let x = {"ham", "cheese", "jam", "bread", "eggs", "brain", "jam", "eggs"}
What is len(x) ?
8
6
underfined/error
none of the other options
Leo wants to create a function that will roll a dice. Which is the correct function definition header?
def dice roll():
def diceroll()
def dice_roll():
def diceroll[]:
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which is a correctly declared tuple?
a = ("orange", "yellow", "red")
a = "orange", "yellow", "red"
a = ["orange", "yellow", "red"]
a = "orangeyellowred"
Which line of code will give you an error? b = (4, 5, 6, 7, 8)
b[2]
b[0] = 1
b[:3]
b[-2]
How would you refer to 3 in the following tuple? c = ((7,5),(5,8),(0,-1),(4,3))
c[0][0]
c(3)
c[8]
c[3][1]
What will be the output of the following Python code?
x = {4,7,8,8,9}
print(x)
{4, 7, 9}
{8, 9, 4, 7}
{4, 7, 8, 8, 9}
Error
Which of the following statements is true for objects of Python’s set type:
The order of elements in a set is significant
A given element can’t appear in a set more than once
Sets are of fixed length
A set may contain elements that are mutable
Consider this dictionary:
d = {'foo': 100, 'bar': 200, 'baz': 300}
What is the result of this statement:
d['bar':'baz']
It raises an exception
(200, 300)
200 300
[200, 300]
What would be the output of the following code snippet?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
for key in a_dict:
print(key)
'blue'
'apple'
'dog'
color
fruit
pet
blue
apple
dog
'color'
'fruit'
'pet'
Which of the following will give you an error?
Suppose dict1={"a":1,"b":2,"c":3}
print(len(dict1))
print(dict1.get("b"))
dict1["a"]=5
None of these
Which of these data types can be used as Keys in a Dictionary? (pick all that apply)
string
set
boolean
tuple
list
Which code should we use to display our graphs?
plt.display()
plt.graph()
plt.show()
plt.chart()
Which library is the most used visulization library in python?
Visual
Matlibplot
Matplotlib
matlab
Which function of matplotlib can be used to create a line chart?
Line
Plot
Graph
Bar
Which graph should be used If we want to find patterns in data?
bar
histogram
scatterplots
basemap
np.arange(2,8,1) ----> what output will be produced?
2,3,4,5,6,7,8
2,3,4,5,6,7,8,9
2,3,4,5,6,7
2,4,6,8
Which one is the correct syntax to import the library for the data visualisation?
import matplotlib
import matplotlib as pyplot
import pyplot
import matplotlib.pyplot as plt
What is the most suitable graph to display the distribution of commission earned by employees? This visualisation shows commission as categories and the number of people in each category.
bar chart
scatter plot
line graph
histogram
What would be a suitable visualisation for showing changes in revenue of a company over a period of 24 months?
scatter diagram
pie chart
histogram
line graph
What would be a suitable visualisation to present student's country of birth, considering a population of a single Computing group?
bar chart
pie chart
scatter diagram
tree map
Mode in the following program to open file for writing in a mode where new data will be added at the end of old data
file =open("poem.txt","__")
r
w
a
r+
What will be the ouput -
f=open('abc.txt','w')
x=f.read()
f.close()
print(x)
Error(not readable)
Error(not writable)
It will read all the data of the file.
none
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
The readlines() method returns
a. str
b. a list of lines
c. a list of single characters
d. a list of integers
What will be the output of the following Python code?
True
False
None
error
What does CSV stand for?
Cursor Separated Variables
Comma Separated Values
Cursor Separated Values
Cursor Separated Version
When iterating over an object returned from csv.reader(), what is returned with each iteration?
For example, given the following code block that assumes csv_reader is an object returned from csv.reader(), what would be printed to the console with each iteration?
for item in csv_reader:
print(item)
The column data as a list
The individual value data that is separated by the delimiter
The full line of the file as a string
The row data as a list
write statement to use the required module for working with comma separated values (csv) files.
(a)
What is a class (in python)?
A user-defined prototype for an object that defines a set of attributes that characterize any object of this. The attributes are data members and methods, accessed via dot notation.
A special kind of function that is defined in a class definition.
The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
the system of ordering a society in which people are divided into sets based on perceived social or economic status.
What is an instance in python?
A special kind of function that is defined in a class definition.
The creation of an instance of a class.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
A moment in time
What is a method in python?
a way of doing something
a special kind of function that is defined in a class definition
the creation of an instance of a class
orderliness of thought or behavior; systematic planning or action
What is an object in python?
A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.
A special kind of function that is defined in a class definition.
The assignment of more than one function to a particular operator.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
What will be printed?
nothing
7
z
12
How confident are you about the upcoming AE1: TCA?
I am going to smash it!
I will do well
I will be okay, hopefully
Don't have a good feeling
It will be a disaster :(
