Python Basics Quiz
This is a quiz for the Telegram quiz challenge/competition. It is meant to be taken by beginners
The Print Function in Python 3:
Question (1):
What will be the output of the code
Options:
"Python quiz for beginners"
Python quiz for beginners
NameError: name "Print" is not defined
None of the above.
Explanation:
This will give a NameError. In Python 3 the built-in print function is defined as print () and not Print (). The letter p is not capitalised.
Question (2):
What will be the output of the code ?
Options:
message
Python quiz for beginners
"Python quiz for beginners"
NameError: name "Print" is not defined
Explanation:
we declared a variable named message and then extracted it when printed. This is used to make the code more readable and easily reusable.
Question (3):
How do you print a string and an integer?
Options:
print("My age is " + 19)
print("My age is " + str(19))
print("My age is " + int(19))
print("My age is " + float(19))
Explanation:
The print function can only print out data types that are the same. It will not concatenate an integer with a string. So the interger needs to be converted into a string by using str(19).
Question (4):
What will be the output of the code ?
Options:
0
10
16
1
Explanation:
The hexadecimal numerical system is a base of 16. so 0x10 will be 16.
Question (5):
what type of iteration is the while loop used ?
Options:
definite
indefinite
indeterminate
limited
explanation:
Question (6):
what will be the output of the code?
options:
2. ('baz', 3)
('bar', 1.34)
('foo', 2.0)
Done.
Question (7):
what will be the output of the function ?
options:
(7,2)
72
9
NameError
Explanation:
Question (8):
which of the following assigns the value 79 to the variable prime_number ?
options:
prime_number := 79
prime_number <- 79
let prime_number = 79
prime_number = 79
Explanation:
In Python a varibale does not need to be declared before it can be used. To create a variable you just assign it a value using the "=" sign.
Question (9):
What will be the result of this code ?
options:
x does not equal to two.
2
x equals two!
(1+3) - 2
Explanation:
x = (1+3) -2 = 2. hence the first statement will be executed.
Question (10):
What will be the value of x printed ?
Options:
3 8 2
13
3 4 5 6 7
3 5 7
Explanation:
The range function is defined as follows: range(start, stop, step). So the range will start from 3 and will be incremented by 2 until it get to 8. so the sequence of numbers printed will be 3 5 7
Question (11):
what will be the output of the code?
Options:
color fruit pet
"color" "fruit" "pet"
blue apple dog
"blue" "apple" "dog"
Explanation:
The for loop is the simplest way to iterate through a dictionary. In Python 3.6 and beyond, the keys and values of a dictionary are iterated over in the same order in which they were created
Question (12):
What will be the result of the code snippet ?
Options:
"Python for beginners"
srennigeb rof nohtyP
"srennigeb rof nohtyP"
None of the above
Explanation:
The slice statement [: : -1] is tused to reverse the
Question (13):
What will be the result ?
Options:
{1, 2, 3}
{1,2,3,4,5}
{3,4,5}
{1,2,3,3,4,5}
Explanation:
The python set union() returns a new set which is a combination of the distinct elements from the two sets. 3 is common from both sets and hence it will not be repeated so the result will be {1,2,3,4,5}
Question (14):
Are both conditions True ?
Options:
Yes
No
Explanation:
The number 200 is bigger than 33 and 500 is also greater than 33. so both statements are True.
Question (15):
What will be the output of the code ?
options:
(1880, 2560)
the 'break' statement is used to exit a 'for' and a 'while' loop
In Python, a function is defined using the block keyword "def" followed by a function's name as the block's name. a function only runs when it is called.
Hello From My Function
A list: [1, 2, 3
x: 10 y: 5
938477566 : Karabo tebogo : 938377264 katlego
the slice statement
[::-1]
means start at the end of the string and end at position 0, move with the step-1
, negative one, which means one step backwards.{1: 1, 2: 4, 3: 9, 5: 25} {1: 1, 2: 4, 4: 16, 3: 9, 5: 25}
{1: 1, 2: 4, 4: 16, 3: 9, 5: 25}
Last updated