WorksheetsPython - variables, syntax and text manipulation
Total questions: 40
Worksheet time: 22mins
The correct syntax of the len function to return the length of the variable x:
x.len()
len[x]
LEN[]
len(x)
The correct syntax for converting the variable x to uppercase is :
X.upper()
upper(x)
x.UPPER[ ]
x.upper()
The correct syntax for converting the variable myname to lowercase is :
myNAME.lower[ ]
myname.lower( )
myname.upper( )
myname_lower(12 )
Let x= "Python", the output of print(x.upper()) is
python
PYTHON
_PYTHON
"PYTHON"
Let x= "Python", the output of
print(x[0])
print(x[1])
print(x[2])
PYT
P
y
t
T
h
o
n
oh
For text, the + operator represents
Concatenation
Addition
Appending
Recantation
data = "No Way!"
The code print(len(data)) would output:
7
9
8
6
What will the output be from the following code?
print("Hello world!" * 2)
TypeError
Hello world world!
Hello world!Hello world!
Hello world! * 2
What will the output be from the following code?
print("3+4")
7
34
3+4
SyntaxError
print("12"*3)
What would this print?
121212
36
24
12*3
print("Hello" + "world" + "today")
Syntax Error
print(Hello world!)
Syntax Error
print("Hello world!")
Print("Hello world!")
Syntax error
Which function takes allows the user to enter data into the program?
Each item in a word has an "address" or index. The first index in a Python string is what?
0
1
a
A
What symbol do you use to declare a comment in Python?
What character will be printed on the screen after running this Python code:
a
l
L
Nothing is printed
What output will this Python code produce?
Kuala Lumpur
11
12
x
What will this print to the screen?
print(2*4)
2*4
8
4
error
What will be printed to the screen?
5
10
5 + 10
15
Num = 90
Num = 20
print(Num)
90
4.5
20
1800
It displays an output message
What is the definition for a VARIABLE?
It stores a value within a program that can change
It allows the algorithm to make a selection
It is a set of precise instructions to solve a problem
It stores a value within a program which stays the same
Choose all rules for naming a variable from the list below:
Must not begin with a number
Can only contain (A-Z, a-z) and 0-9 characters, and _
It can't contain a space
Must be in lower case
Choose all valid variable names from the list of options given below:
1st_name
Last_name
first Name
f1_name
firstName
Which of the below are acceptable variable names?
result final = 5
result-final = 1
resultFinal = 3
result#final = 4
What is the name of the variable in this program?
colour
input
" "
print("Python " * 3); will print out what
Python 3 Python 3 Python 3
Python Python Python
PythonPythonPython
Python*3 Python*3 Python*3
Which of the following statements assigns the value 100 to variable x in python
Let x=100
x=100
x:=100
x==100
What will be output of the following code be?
1var = 6
6
1
var
Syntax error
What will the output of the following code be?
a = 5
b = 0
print(a)
5
0,5
0
5
5
5
What symbol is used for multiplication in Python coding?
x
+
#
*
print(3+4)
print("3+4")
What will be the output?
name = "Dave"
print ("name")
Dave
"Dave"
name
(name)
