WorksheetsPython
Total questions: 120
Worksheet time: 1hrs 14mins
print(Hello world!)
print("Hello world!")
print(3+4)
print("3+4")
What will the output be from the following code?
print("Hello world!\nHello world!") (aka new line)
Hello world! Hello world!
Hello world!
Hello world!
SyntaxError
Hello world!
What is syntax?
Syntax is the word used to describe an error
Syntax is the rules of the programming language
It is used to read information
It is used to output information
print("Hello" + "world!")
print("Hello" + "world" + "today")
What symbol is used in python to assign values to a variable? x=coat
equals =
plus +
forward slash /
asterisk *
name = 'Dave'
print (name)
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
Good morning 'Dave'
Good morning Dave
Good morning name
Good morning + Dave
What would be an example of an integer or whole number?
4
2.5
7.4
9.4
Everything that we want do display in a print() function must:
be inside parentheses - ()
quotation marks - ""
be inside single quotation marks - ''
be inside hash marks - #
Comments are added in programming to explain what's going on in the code. The computer does not recognize comments. How do you start a comment?
With a ?
With a #
With an !
With a &
In Python, variables are black, functions are purple and strings are green? True or False
True
False
To display something on the screen, use this command:
print()
Print()
screen()
write()
display()
To display the following on screen
Hello World!
the following command should be used:
print(Hello World!)
print("Hello World!")
print("Hello World" + !)
print"(Hello World!)"
name = 'Dave'
print (name)
Which operator performs a division?
-
+
/
*
Which operator checks if a value is equal to another value?
+
=
==
!=
Which operator checks if a value is not equal to another value?
==
+=
!=
=
Which of the following is correct?
Comments are for programmers for better understanding of the program.
Python Interpreter ignores comment.
You can write multi-line comments in Python using triple quotes, either ''' or """.
All of the above
In the following code, n is a/an _______?
n = '5'
integer
string
tuple
operator
What is used to take input from the user in Python?
cin
scanf()
input()
<>
What is a input?
A built-in function that allows us to prompt the user to enter data.
To plug in something.
Data displayed on a screen.
A device.
What syntax would you use to create a name variable?
name=input()
input=name
name=input{}
name=INPUT
print("Hello world!\nHello world!")
Hello world!
Syntax Error
print("Hello" + str(2) + "world!")
Syntax Error
What does the following code do? myAge = int(myAge)
Converts the variable myAge to a integer
Syntax Error
Converts the variable myAge from a integer to a string
Missing input
Are Double or single quotes used in Python?
Double
Single
Neither
Both work
Python correct naming convention for variables is?
new_user25
NewUser25
25_new_user
25NewUser
NEWUSER25
The output of the program
x = 4
x = "Sally"
print(x)
four
Saly
Sally
4
print("Hello" + 2 + "world")
print("3+4")
print(3+4)
What is the name of the variable in this program?
colour
input
" "
What will be the output for following python programme:
x = 100
y = float(x)
print(y)
200
100.0
100
Can't convert an integer to a floating number.
Which of the statements below is true about indentation in Python?
Indentation only matters in for loops. Then, everything must be indented one level.
Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.
Indentation always matters in Python. Every statement must be aligned correctly.
Indentation only matters in functions. Then, everything must be indented one level.
Which one is NOT a legal variable name?
_fname
first_Name
f-Name
Fname
What is the correct syntax to output the type of a variable or object in Python?
print(type(x))
print(typeof(x))
print(type of (x))
print(typeOf(x))
In Python, 'Hello', is the same as "Hello"
True
False
Cant say
both are wrong
What is the correct file extension for Python files?
.pyth
.py
.pt
.pyt
Who developed the Python programming language?
Rasmus Lerdorf
Wick van Rossum
Guido van Rossum
Guido Van Stom
Full form of IDLE in python is:
(a)
a > b
a >= b
my number = 36
print("Hello world!" * 2)
(a) is smallest individual unit in a program.
Size of the string "Ant Man"
(a)
To create a set, the following would be used -
( )
[ ]
{ }
{ key : value }
To create a list, the following would be used -
( )
[ ]
{ }
{ key : value }
To create a tuple, the following would be used -
( )
[ ]
{ }
{ key : value }
To create a dictionary, the following would be used -
( )
[ ]
{ }
{ key : value }
What type of data collection is this?
[ 3, 4, 5, 6 ]
Dictionary
List
Set
Tuple
What type of data collection is this?
( 3, 4, 5, 6 )
Dictionary
List
Set
Tuple
What type of data collection is this?
{ 3, 4, 5, 6 }
Dictionary
List
Set
Tuple
What type of data collection is this?
{ student: "Bill", grade: 92, class: "Python" }
Dictionary
List
Set
Tuple
What is a list in python?
A collection of variables
A collection of items assigned to a single variable
A statement that cant be changed
A Christmas list
Which of these codes is correct for creating a list of numbers?
num = ('10','29','37','109')
num = ['10','29','37','109']
num == ('10','29','37','109')
num = ['10 29 37 109']
What is the index number for 'Spain'?
['England','Brazil','Spain','France']
0
1
2
3
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
variable.sort() will do what?
Sort the list into alphabetical order
Sort the list into reverse order
Create a new list
Error
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]
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
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 would this code show on the screen?
7
6
5
4
An error
Each item in a list has an "address" or index. The first index in a Python list is what?
1
0
a
A
What is the output of program below?
mariana_islands = ['Saipan', 'Tinian', 'Rota']
del mariana_islands[0]
print(mariana_islands)
['Saipan', 'Tinian', 'Rota']
['Tinian', 'Rota']
['Saipan', 'Tinian']
['Saipan', 'Rota']
What is the output of program below?
mariana_islands = ['Saipan', 'Tinian', 'Rota']
mariana_islands[0] = 'Guam'
print(mariana_islands)
['Saipan', 'Tinian', 'Rota']
['Guam', 'Tinian', 'Rota']
['Saipan', 'Tinian', 'Rota', 'Guam']
['Guam', 'Saipan', 'Tinian', 'Rota']
nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]
The list will be slice and show Harry and Jesse only. Which piece of code below would do this?
print(nameList[1:3])
print(nameList[0:1])
print(nameList[1:2])
print(nameList["Harry":"Jesse"])
Tuples in Python are mutable
False
True
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
What will be the output?
var1=['sam', "Pam", 12,44]
var1[3]="Ram"
print(var1)
['sam', 'Pam', 12, 44]
['sam', 'Pam', 12, 'Ram']
It will give an error
['sam', 'Pam', 'Ram',44]
The code snippet above outputs
error
None
NaN
-1
Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.
grades[102]
grades.get(102)
grades[2]
grades[3]
grades.key(102)
Which of the following statements is used to create an empty set?
{ }
set()
[ ]
( )
If a={5,6,7}, what happens when a.add(5) is executed?
a={5,5,6,7}
a={5,6,7}
Error as there is no add function for set data type
Error as 5 already exists in the set
What will be the output of the following Python code?
>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a
{2,3}
Error, duplicate item present in list
Error, no method called intersection_update for set data type
{1,4,5}
What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a.copy()
>>> b.add(4)
>>> a
{1,2,3}
Error, invalid syntax for add
{1,2,3,4}
Error, copying of sets isn’t allowed
What will be the output of the following Python code?
s=set()
type(s)
<’set’>
<class ‘set’>
set
class set
Select all of the types of data collections that are ORDERED.
(that means items can be referenced by location or key)
Dictionary
List
Tuple
Set
Select all of the types of data collections that ALLOW duplicate values.
Dictionary
List
Tuple
Set
Select all of the types of data collections that ALLOW individual items within the collection to be changed or modified.
Dictionary
List
Tuple
Set
Which command will allow you to attempt to remove an item from a set without raising an error if it isn't in the set.
.remove( )
.discard( )
.pop( )
.delete( )
Which command will allow you to remove the last item in a collection.
.remove( )
.discard( )
.pop( )
.delete( )
Which command will allow you to attempt to remove an item from a set and will raise an error if it isn't in the set
.remove( )
.discard( )
.pop( )
.delete( )
Which method will combine the contents of two sets WITHOUT changing one of the existing sets?
.update( )
.union( )
.add( )
.intersection( )
