Python Programming Ultimate Quiz: Test!

37 Questions | Total Attempts: 5667

SettingsSettingsSettings
Please wait...
Python Programming Quizzes & Trivia

Python is a high-level programming language that allows the user to focus on the core functionality of the python application and it can be used to build just about anything with the right tools. Python supports modules and packages, which encourages program modularity and code re-use. Test your understanding of Python programming by taking up the test below. All the best!


Questions and Answers
  • 1. 
    Which of the following is not a valid data type in python? 
    • A. 

      Int

    • B. 

      Float

    • C. 

      Double

    • D. 

      Str

  • 2. 
    Complete the code to print the following numbers:13579for i in range(1, 10, __):    print i
  • 3. 
    Complete the code to print the following patterns: 1 1 1 1 12 2 2 2 23 3 3 3 34 4 4 4 45 5 5 5 5 for i in range(1, 6, 1):    print ____ * 5
  • 4. 
    Study the code below: for i in x:   print iWhich of the option below is incorrect?
    • A. 

      X is a str

    • B. 

      X is an int

    • C. 

      X is ant list

    • D. 

      X is a tuple

  • 5. 
    Refer to the the code below:a_list = [10, 20, 30, 40].What is the value of a_list[-1]?
    • A. 

      10

    • B. 

      20

    • C. 

      30

    • D. 

      40

  • 6. 
    Refer to the the code below:a_list = [10, 20, 30, 40].What is the value of a_list[-2]?
    • A. 

      10

    • B. 

      20

    • C. 

      30

    • D. 

      40

  • 7. 
    Fill in the blank to produce the following output:[11, 22, 33, 44, 55, 66, 77, 88]print range(11, 90, __ )
  • 8. 
    Which of the following is NOT a valid call to the function funA?def funA(a, b):    print a + int(b)
    • A. 

      FunA(3, 4.0)

    • B. 

      FunA(3, "4.0")

    • C. 

      FunA("3", 4.0)

    • D. 

      FunA("3", "4.0")

  • 9. 
    What is the value of a?a  = 1 == 1 and not 1 != 1a = _____
  • 10. 
    What is the value of x?x= 0for i in range(2, 20, 3):  if i %2 == 0:      x += 1print x
    • A. 

      2

    • B. 

      3

    • C. 

      4

    • D. 

      5

  • 11. 
    Study the code given below:import randomx = random.randint(1,6)y = random.randint(1,6)z = random.randint(1,6)a = x + y + zWhat is the possible range of values for a?
    • A. 

      1 to 6

    • B. 

      1 to 12

    • C. 

      1 to 18

    • D. 

      3 to 18

  • 12. 
    Colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] What is the value of colors[2]?
  • 13. 
    What is the value of x after executing the code shown below?i = 0x = 0while i < 10:    if i % 2 == 0:        x += 1    i += 1x = _____.
  • 14. 
    Which of the following options create an instance of Laptop correctly?class Laptop:    def __init__(self, capacity):        self.capacity = capacity        self.color = 'green'
    • A. 

      Laptop = Laptop(2000, 'green')

    • B. 

      Laptop = Laptop()

    • C. 

      Laptop = Laptop(2000)

    • D. 

      Laptop = Laptop('green')

  • 15. 
    Which of the following options create an instance of Laptop and change the color of the laptop to white correctly?class Laptop:    def __init__(self, capacity):        self.capacity = capacity        self.color = 'green'    def change_color(self, new_color):       self.color = new_color
    • A. 

      Laptop = Laptop() laptop.change_color('white')

    • B. 

      Laptop = Laptop(2000, 'green') laptop.change_color(self, 'white')

    • C. 

      Laptop = Laptop(2000) laptop.change_color('white')

    • D. 

      Laptop = Laptop(2000) laptop.change_color(self, 'white')

  • 16. 
    What is the value of x after executing the code shown below?x = 'hello world'x = x.upper()Value of x is ______
  • 17. 
    A_list = range(2, 11, 2)a_list = a_list[1: -1]Look at the options given, which number is not contained in a_list?
    • A. 

      2

    • B. 

      4

    • C. 

      6

    • D. 

      8

  • 18. 
    Which line of code will add a new element 10 to the end of the list?a_list = [2,4,6,8]
    • A. 

      A_list.insert(10)

    • B. 

      A_list += 10

    • C. 

      A_list.append(10)

    • D. 

      A_list.add(10)

  • 19. 
    Def funA(a, b):    return a * bdef funB(c, d):   return a + bx = funA(funB(3,4), 5)What is the value of x after executing the code shown above?x = ____
  • 20. 
    Which of the following is not a valid function name?
    • A. 

      1function

    • B. 

      Function1

    • C. 

      Function_1

    • D. 

      Func_1_tion

    • E. 

      _function1

  • 21. 
    Study the code below.x = 1y = 3In Python, x/y returns you 0, which is wrong. Which of the solutions below will fix this.
    • A. 

      Use float(x/y) instead.

    • B. 

      Use float(x)/y instead.

    • C. 

      Use x.0 / y.0 instead.

    • D. 

      Use x // y instead.

  • 22. 
    To print out the text as shown below, what code should we execute?I love to take a ride in his sport's car!
    • A. 

      Print 'I love to take a ride in his sport's car!'

    • B. 

      Print 'I love to take a ride in his sport"s car!'

    • C. 

      Print "I love to take a ride in his sport's car!"

    • D. 

      Print I love to take a ride in his sport's car!

  • 23. 
    X = "1"y = 10Pick the code which will produce an error when executed.
    • A. 

      Print x + str(y)

    • B. 

      Print int(x) + y

    • C. 

      Print str(x) + str(y)

    • D. 

      Print int(x) + float(y)

    • E. 

      Print x + y

  • 24. 
    A function, convert_to_grade takes in a number and returns the letter grade for it.Another function, convert_to_text takes in a letter grade and returns some words of encouragement based on the letter grade.If you would like to get some words of encouragement for someone who scored 20 marks, what code should be executed?
    • A. 

      Print convert_to_text(convert_to_grade(20))

    • B. 

      Print convert_to_grade(convert_to_letter(20))

    • C. 

      Print convert_to_text(20)

    • D. 

      Print convert_to_grade(convert_to_grade(20))

    • E. 

      Print convert_to_text(convert_to_text(20))

  • 25. 
    My_list = [1,3,5,7,9,11]Which of the following code will produce the same contents for my_list_2 as that stored in my_list?
    • A. 

      My_list2 = range(1,3,5,7,9,11)

    • B. 

      My_list2 = range(1,11,2)

    • C. 

      My_list2 = range(1,12,1)

    • D. 

      My_list2 = range(1,13,1)

    • E. 

      My_list_2 = range(1,13,2)