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:

  1. "Python quiz for beginners"

  2. Python quiz for beginners

  3. NameError: name "Print" is not defined

  4. 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:

  1. message

  2. Python quiz for beginners

  3. "Python quiz for beginners"

  4. 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:

  1. print("My age is " + 19)

  2. print("My age is " + str(19))

  3. print("My age is " + int(19))

  4. 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:

  1. 0

  2. 10

  3. 16

  4. 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:

  1. definite

  2. indefinite

  3. indeterminate

  4. limited

explanation:

Question (6):

what will be the output of the code?

options:

  1. ('baz', 2.0)
    ('bar', 2)
    ('foo', 1)
    Done.

2. ('baz', 3)

('bar', 1.34)

('foo', 2.0)

Done.

Question (7):

what will be the output of the function ?

options:

  1. (7,2)

  2. 72

  3. 9

  4. NameError

Explanation:

Question (8):

which of the following assigns the value 79 to the variable prime_number ?

options:

  1. prime_number := 79

  2. prime_number <- 79

  3. let prime_number = 79

  4. 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:

  1. x does not equal to two.

  2. 2

  3. x equals two!

  4. (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:

  1. 3 8 2

  2. 13

  3. 3 4 5 6 7

  4. 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:

  1. color fruit pet

  2. "color" "fruit" "pet"

  3. blue apple dog

  4. "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:

  1. "Python for beginners"

  2. srennigeb rof nohtyP

  3. "srennigeb rof nohtyP"

  4. None of the above

Explanation:

The slice statement [: : -1] is tused to reverse the

Question (13):

What will be the result ?

Options:

  1. {1, 2, 3}

  2. {1,2,3,4,5}

  3. {3,4,5}

  4. {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:

  1. Yes

  2. 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:

  1. (1880, 2560)

  2. the 'break' statement is used to exit a 'for' and a 'while' loop

  3. 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.

  4. Hello From My Function

  5. A list: [1, 2, 3

  6. x: 10 y: 5

  7. 938477566 : Karabo tebogo : 938377264 katlego

  8. 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.

  9. {1: 1, 2: 4, 3: 9, 5: 25} {1: 1, 2: 4, 4: 16, 3: 9, 5: 25}

    1. {1: 1, 2: 4, 4: 16, 3: 9, 5: 25}

Last updated