Font size
WorksheetsPython list, if
Total questions: 20
Worksheet time: 11mins
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")
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"])
To insert an the string "Pedro" in the first position of a the nameList we use
nameList.append("Pedro, 1")
nameList.insert("Pedro",0)
nameList.insert(1, "Pedro")
nameList.insert(0, "Pedro")
variable.sort() will do what?
Sort the list into alphabetical order
Sort the list into reverse order
Create a new list
Error
nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]
print(nameList.count("John"))
What would be the output
1
2
3
Error
nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]
nameList[6] ="Susie"
print(nameList)
What would be the output
['John', 'Harry', 'Jesse', 'John', 'Marry', 'Larry', 'Susie']
['Susie', 'John', 'Harry', 'Jesse', 'John', 'Marry', 'Larry']
['Susie']
Error
What does the following code do? myAge = int (myAge)
Converts the var (variable) myAge to a string
Converts the var (variable) myAge to a integer
Converts the var (variable) myAge from a integer to a string
Converts the var (variable) myAge to if statement
print(Hello world!)
people = ["John", "Rob", "Bob"]
print (people[1])
what would this result be?
The ‘else’ statement is optional in Python
TRUE
FALSE
There can be an else statement without an if statement
FALSE
TRUE
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
Write the symbol for the blank space, if an adult's age is 18 or above.
if age (a) 18: print("You are an adult")
elif age<18: print("You are a child")
The result of this program:
Friday = False
if Friday:
print "Jeans day!"
else:
print "Uniform day"
Jeans day
Today is Friday
Uniform day
Not Friday
What is the output?
True
NIL
True
NIL
True
NIL
NIL
