Python
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car["color"] = "red"
Add the key/value pari "color" : "red" to the 'car' dictionary car = { "brand": "Ford", "model": "Mustang", "year": 1964 } _______ ___ _____
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car["year"] = 2020
Change the "year" value from 1964 to 2020 car = { "brand": "Ford", "model": "Mustang", "year": 1964 } _______
fruits = ["apple", "banana", "cherry"] fruits[0] = "kiwiw'
Change the value from "apple" to "kiwi", in the 'fruits' list fruits = ["apple", "banana", "cherry"] _______ = _____
fruits = {"apple", "banana", "cherry"} if "apple" in fruits: print("Yes, apple is a fruit!")
Check if "apple" is present in the 'fruits' set fruits = {"apple", "banana", "cherry"} if "apple" ___ fruits: print("Yes, apple is a fruit!")
# This is a comment
Comments in Python are written with a special character, which one? __ This is a comment
txt = "Hello World" txt = txt.lower( )
Convert the value of "txt" to lower case txt = "Hello World" txt = _____
txt = "Hello World" txt = txt.upper( )
Convert the value of 'txt' to upper case txt = "Hello World" txt = _____
txt.upper( )
Convert the value of txt to upper case: txt = "Hello World"
class MyClass: x = 5
Create a class named MyClass: _____ MyClass: x = 5
def my_function( ): print("Hello from a function")
Create a function named my_function: _____________: print("Hello from a function")
x = lambda a : a
Create a lambda function that takes one parameter ('a') and returns it x = _______ __ __ __
x = 5 y = 10 x = x + y print(z)
Create a variable called 'z', assign 'x + y' to it, and display the result x = 5 y = 10 __ = x + y print(__)
x = 50
Create a variable name 'x' and assign the value 50 to it
carname = "Volvo"
Create a variable named 'carname' and assign the value 'Volvo' to it __ = "__"
class MyClass: x = 5 p1 = MyClass( )
Create an object MyClass called p1: class MyClass: x = 5 p1 = MyClass( )
x = 5 y = 10 print(x + y)
Display the sum of 5 + 10, using two variables: 'x' and 'y' __ = __ y = 10 print(x __ y)
print(10 / 2)
Divide 10 by 2, and print the result print(10 _ 2)
def my_function( ): print("Hello from a function") my_function( )
Execute a function name my_function def my_function( ): print("Hello from a function") _______________
fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": break print(x)
Exit the loop when 'x' is "banana" fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": _____ print(x)
txt = "Hello World" x = txt[2:5]
Get the characters from index 2 to index 4 (llo) txt = "Hello World" x = _____
txt = "Hello World" x = txt[0]
Get the first character of the string 'txt' txt = "Hello World" x = _____
def my_function(*kids): print("The youngest child is " + kids[2])
If you do not know the number of arguments that will be passed into your function, there is a prefix you can add in the function definition, which prefix? def my_function(__kids): print("The youngest child is " + kids[2])
def my_function(**kids): print("The youngest child is " + kids[2])
If you do not know the number of keyword arguments that will be passed into your function, there is a prefix you can add in the function definition, which prefix? def my_function(___kids): print("The youngest child is " + kids[2])
import mymodule as mx
If you want to refer to a module by using a different name, you can create an alias What is the correct syntax for creating an alias for a module? import mymodule ___ mx
i = 0 while i < 6: i += 1 if i == 3: continue print(i)
In the loop, when 'i' is '3', jump to the next iteration i = 0 while i < 6: i += 1 if i == 3: _______ print(i)
fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x)
In the loop, when the item value is "banana", jump directly to the next item fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": _______ print(x)
def myfunc( ): global x x = "fantastic"
Insert the correct keyword to make the variable x belong to the global scope def myfunc( ): _____ x x = "fantastic"
age = 36 txt = "My name is John, and I am { }" print(txt.format(age))
Insert the correct syntax to ass a placeholder for the age parameter age = 36 txt = "My name is John, and I am __" print(txt.format(age))
x = y = z = "Orange"
Insert the correct syntax to assign the same value to all three variables in one code line. x __ y __ z __ "Orange"
x = 5 x = complex(x)
Insert the correct syntax to convert x into a complex number x = 5 x = ___(x)
x = 5 x = float(x)
Insert the correct syntax to convert x into a floating point number x = 5 x = ___(x)
x = 5.5 x = int(x)
Insert the correct syntax to convert x into a integer x = 5.5 x = ___(x)
if 5 > 2: print("Five is greater than two!")
Insert the missing indentation to make the code correct: if 5 > 2: print("Five is greater than two!")
def my_function(fname, lname): print(fname)
Inside a function with two parameters, print the first parameter def my_function(fname, lname): print(_____)
def my_function(x): return x + 5
Let the function return the 'x' parameter + 5 def my_function(x): ________ ___ __ ___
fruits = ["apple", "banana", "cherry"] for x in fruits: print(x)
Loop through the items in the 'fruits' list fruits = ["apple", "banana", "cherry"] ____ x ___ fruits__ print(x)
print(10 * 5)
Multiply 10 with 5, and print the result print(10 _ 5)
a = 50 b = 10 if a == b: print("1") elseif a > b: print("2") else: print("3")
Print "1" if 'a' is equal to 'b', print "2" is 'a' is greater than 'b', otherwise print "3" a = 50 b = 10 __ a ___ b__ print("1") _____ a __ b__ print("2") _____ print("3")
a = 50 b = 10 If a > b: print("Hello World")
Print "Hello World" if 'a' is greater than 'b' a = 50 b = 10 __ a __ b__ print("Hello World")
a = 50 b = 10 If a !> b: print("Hello World")
Print "Hello World" if 'a' is not equal to 'b' a = 50 b = 10 __ a __ b__ print("Hello World")
if a == b and c == d print("Hello")
Print "Hello" is 'a' is equal to 'b', and 'c' is equal to 'd' if a == b ___ c == d print("Hello")
if a == b or c == d print("Hello")
Print "Hello" is 'a' is equal to 'b', or 'c' is equal to 'd' if a == b ___ c == d print("Hello")
a = 50 b = 10 if a == b: print("Yes") else: print("No")
Print "Yes" if 'a' is equal to 'b', otherwise print "No" a = 50 b = 10 __ a ___ b__ print("Yes") _____ print("No")
i = 1 while i < 6: print(i) i += 1
Print 'i' as long as 'i' is less than 6 i = 1 _____ i < 6__ print(i) i += 1
i = 1 while i < 6: print(i) i += 1 else: print("i is no longer less than 6")
Print a message once the condition is false i = 1 while i < 6: print(i) i += 1 _____ print("i is no longer less than 6")
fruits = ["apple", "banana", "cherry"] print(fruit[1])
Print the second item in the 'fruits' list fruits = ["apple", "banana", "cherry"] print(_____)
myfirst_name = "John"
Remove the illegal characters in the variable name: 2my-first_name = "John"
txt = "Hello World" txt = txt.replace("H", "J")
Replace the character H with a J txt = "Hello World" txt = txt._____(___,___)
txt = " Hello World " x = txt.strip( )
Return the string without any whitespace at the beginning or the end txt = " Hello World " x = _____
i = 1 while i < 6: if i == 3: break i += 1
Stop the loop if 'i' is 3 i = 1 while i < 6: if i == 3: _____ i += 1
x = "Hello World" print(type(x)) str
The following code example would print the data type of x, what data type would that be? x = "Hello World" print(type(x))
x = ("apple", "banana", "cherry") print(type(x)) tuple
The following code example would print the data type of x, what data type would that be? x = ("apple", "banana", "cherry") print(type(x))
x = 20.5 print(type(x)) float
The following code example would print the data type of x, what data type would that be? x = 20.5 print(type(x))
x = 5 print(type(x)) int
The following code example would print the data type of x, what data type would that be? x = 5 print(type(x))
x = True print(type(x)) bool
The following code example would print the data type of x, what data type would that be? x = True print(type(x))
x = ["apple", "banana", "cherry"] print(type(x)) list
The following code example would print the data type of x, what data type would that be? x = ["apple", "banana", "cherry"] print(type(x))
x = {"name" : "John", "age" : 36} print(type(x)) dict
The following code example would print the data type of x, what data type would that be? x = {"name" : "John", "age" : 36} print(type(x))
print(10 < 9) False
The statement below would print a Boolean value, which on ? print(10 < 9)
print(10 == 9) False
The statement below would print a Boolean value, which one? print(10 ==9)
Print(10 > 9) True
The statement below would print a Boolean value, which one? print(10 > 9)
print(bool("abc")) True
The statement below would print a Boolean value, which one? print(bool("abc"))
print(bool(0)) False
The statement below would print a Boolean value, which one? print(bool(0)
""" This is a comment written in more than just one line """
Use a multiline string to make the a multi line comment: __ This is a comment written in more than just one line __
fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(fruits[2:5])
Use a range of indexes to print the third, fourth, and fifth item in the list fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(fruits[___])
fruits = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(fruits[2:5])
Use a range of indexes to print the third, fourth, and fifth item in the tuple fruits = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(fruits[___])
fruits = ["apple", "banana", "cherry"] print(fruits[-1])
Use negative indexing to print the last item in the list fruits = ["apple", "banana", "cherry"] print(_____)
fruits = ("apple", "banana", "cherry") print(fruits[-1])
Use negative indexing to print the last item in the tuple fruits = ("apple", "banana", "cherry") print(_______)
fruits = {"apple", "banana", "cherry} fruits.add("orange")
Use the 'add' method to add "orange" to the 'fruits' set fruits = {"apple", "banana", "cherry"} _______
fruits = ["apple", "banana", "cherry"] fruits.append("orange")
Use the 'append' method to add 'orange' to the 'fruits' list fruits = ["apple", "banana", "cherry"} ____________
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.clear( )
Use the 'clear' method to empty the 'car' dictionary car = { "brand": "Ford", "model": "Mustang", "year": 1964 } _______
fruits = {"apple", "banana", "cherry"} fruits.discard("banana")
Use the 'discard' method to remove "banana" from the 'fruits' set fruits = {"apple", "banana", "cherry"} _______
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } print(car.get("model"))
Use the 'get' method to print he value of the "model" key of the 'car' dictionary car = { "brand": "Ford", "model": "Mustang", "year": 1964 } print(_______)
fruits = ["apple", "banana", "cherry"] fruits.insert(1, "lemon")
Use the 'insert' method to add "lemon" as the second item in the 'fruits' list fruits = ["apple", "banana", "cherry"] _____ "lemon")
x = "HelloWorld" print(len(x))
Use the 'len' method to print the length of the string x = "Hello World" print(_____)
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.pop("model")
Use the 'pop' method to remove "model" from the 'car' dictionary car = { "brand": "Ford", "model": "Mustang", "year": 1964 } _______
for x in range(6): print(x)
Use the 'range' function to loop through a code set 6 times for x in _____: print(x)
fruits = {"apple", "banana", "cherry"} fruits.remove("banana")
Use the 'remove' method to remove "banana" from the 'fruits' set fruits = {"apple", "banana", "cherry"} ______
if 5 != 10 print("5 and 10 is not equal")
Use the correct comparison operator to check if 5 is not equal to 10 if 5 __ 10: print("5 and 10 is not equal")
if 5 == 10 or 4 == 4: print("At least on of the statements is true")
Use the correct logical operator to check if at least one of two statements is true if 5 == 10 __ 4 == 4: print("At least one of the statements is true")
fruits = ["apple", "banana"] if "apple" in fruits: print("Yes, apple is a fruit!")
Use the correct membership operator to check if "apple" is present in the fruits object fruits = ["apple", "banana"] if "apple" __ fruits: print("Yes, apple is a fruit!")
fruits = {"apple", "banana", "cherry"} more_fruits = ["orange", "mango", "grapes"] fruits.update(more_fruits)
Use the correct method to add multiple items(more_fruits) to the 'fruits' set fruits = {"apple", "banana", "cherry"} more_fruits = ["orange", "mango", "grapes"] _______
if 5 > 2: print("Five is greater than two!")
Use the correct short hand syntax to put the following statement on one line: if 5 > 2: print("Five is greater than two!")
print("Yes") if 5 > 2 else print("No")
Use the correct short hand syntax to write the following conditional expression in one line: if 5 > 2: print("Yes") else print("No")
fruits = ("apple", "banana", "cherry") print(fruits[0])
Use the correct syntax to print the first item in the 'fruits' tuple fruits = ("apple", "banana", "cherry") print(_____)
fruits = ("apple", "banana", "cherry") print(len(fruits))
Use the correct syntax to print the number of items in the 'fruits' tuple fruits = ("apple", "banana", "cherry") print(_____)
fruits = ["apple", "banana", "cherry"] print(len(fruits))
Use the correct syntax to print the number of items in the list fruits = ["apple", "banana", "cherry"] print(_______)
class MyClass: x = 5 p1 = MyClass( ) print(p1.x)
Use the p1 object to print the value of x: class MyClass: x = 5 p1 = MyClass( ) print(_____)
class Person: def __init__ (self, fname): self.firstname = fname def printname(self): print(self.firstname) class Student(Person): pass x = Student("Mike") x.printname()
We have used the 'Student' class to create an object named 'x'. What is the correct syntax to execute the 'printname' method to the object 'x'? class Person: def __init__ (self, fname): self.firstname = fname def printname(self): print(self.firstname) class Student(Person): pass x = Student("Mike") __________________
from mymodule import person1
What is the correct syntax of importing only the person1 dictionary of the "mymodule" module? _____ mymodule _______ person1
import mymodule print(dir(mymodule))
What is the correct syntax of printing all variables and function names of the "mymodule" module? import mymodule print(_______)
class Person: def ___init___(self, name, age): self.name = name self.age = age
What is the correct syntax to assign a "init" function to a class: class Person: def _____(self, name, age): self.name = name self.age = age
class Student(Person)
What is the correct syntax to create a class named 'Student' that will inherit properties and methods from a class named 'Person'? class ____________
import mymodule
What is the correct syntax to import a module named "mymodule"? _______ mymodule
fruits = ["apple", "banana", "cherry"] fruits.remove("banana")
use the 'remove' method to remove "banana" from the 'fruits' list fruits = ["apple", "banana", "cherry"] ________