Python Programming Language Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By 96redformy
9
96redformy
Community Contributor
Quizzes Created: 1 | Total Attempts: 785
Questions: 28 | Attempts: 785

SettingsSettingsSettings
Python Programming Language Trivia Quiz - Quiz

.


Questions and Answers
  • 1. 

    Which two lines of code are valid strings in Python?  

    • A.

      This is a string

    • B.

      ‘This is a string’

    • C.

      (This is a string)

    • D.

      “This is a string”

    Correct Answer(s)
    B. ‘This is a string’
    D. “This is a string”
    Explanation
    The two valid strings in Python are 'This is a string' and "This is a string". In Python, strings can be represented using either single quotes or double quotes.

    Rate this question:

  • 2. 

    True or False: A string can be surrounded by three sets of single quotation marks or by three sets of double quotation marks.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    A string can indeed be surrounded by three sets of single quotation marks or by three sets of double quotation marks. This is known as triple quoting and can be used in some programming languages to represent multi-line strings. It provides a convenient way to include special characters, line breaks, and formatting within the string without the need for escape sequences.

    Rate this question:

  • 3. 

    Which line of code has the proper syntax for the print statement?

    • A.

      Print( Its’ a rainy day )

    • B.

      Print( ‘it’s a rainy day’ )

    • C.

      Print( ‘it’s a rainy day” )

    • D.

      Print( ‘it\’s a rainy day’ )

    Correct Answer
    D. Print( ‘it\’s a rainy day’ )
    Explanation
    The line of code "print( ‘it\’s a rainy day’ )" has the proper syntax for the print statement because it uses single quotes to enclose the string and escapes the apostrophe within the string using a backslash.

    Rate this question:

  • 4. 

    You have the following code segment: print(“Here we have a line of text \n and \n we can do newlines!”) What is the output of this code?

    • A.

      Here we have a line of text and we can do newlines!

    • B.

      Here we have a line of text and we can do newlines!

    • C.

      Here we have a line of text and we can do newlines!

    • D.

      Here we have a line of text and we can do newlines!

    Correct Answer
    A. Here we have a line of text and we can do newlines!
    Explanation
    The output of this code will be "Here we have a line of text \n and \n we can do newlines!". This is because the "\n" character is used to represent a newline in Python, so when the code is executed, it will print the text with the newlines intact.

    Rate this question:

  • 5. 

    Which value type does input() return?

    • A.

      Boolean

    • B.

      String

    • C.

      Int

    • D.

      Float

    Correct Answer
    B. String
    Explanation
    The input() function in Python returns a string value. This means that whenever we use the input() function to get user input, the value returned will be in the form of a string. If we want to use this input as an integer or a float, we need to explicitly convert it using the int() or float() functions, respectively.

    Rate this question:

  • 6. 

    True or False: Variables can be assigned only once.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Variables can be assigned multiple times in programming. Once a variable is declared, its value can be changed or updated throughout the program. This allows for flexibility and the ability to store and manipulate different values as needed. Therefore, the statement "Variables can be assigned only once" is false.

    Rate this question:

  • 7. 

    You have the following code segment: myString01 = “my“ myString02 = “string” print(myString01 , myString02) What is the output of this code?

    • A.

      My string

    • B.

      String

    • C.

      Mystring

    • D.

      My

    Correct Answer
    A. My string
    Explanation
    The code segment declares two variables, myString01 and myString02, and assigns them the values "my" and "string" respectively. Then, it prints the values of both variables separated by a space. Therefore, the output of this code will be "my string".

    Rate this question:

  • 8. 

    You have the following code segment: myString01 = “my“ myString02 = “string” print(myString01 + myString02) What is the output of this code?

    • A.

      My string

    • B.

      String

    • C.

      Mystring

    • D.

      My

    Correct Answer
    C. Mystring
    Explanation
    The code segment concatenates the values of myString01 and myString02 using the + operator. The value of myString01 is "my" and the value of myString02 is "string". Therefore, the output of the code is "mystring".

    Rate this question:

  • 9. 

    True or False: A variable is a placeholder for data.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    A variable is a placeholder for data because it is used to store and represent different values or information within a program. It can hold various types of data such as numbers, text, or objects, and its value can be changed throughout the execution of the program. By using variables, programmers can manipulate and work with data in a flexible and dynamic way. Therefore, it is correct to say that a variable acts as a placeholder for data.

    Rate this question:

  • 10. 

    You have the following code segment: myString = “hello world” print( myString.upper() + “ “ + myString ) What is the output of this code?

    • A.

      HELLO WORLD

    • B.

      HELLO WORLD hello world

    • C.

      Hello world hello world

    • D.

      HELLO WORLD HELLO WORLD

    Correct Answer
    B. HELLO WORLD hello world
    Explanation
    The code segment converts the string "hello world" to uppercase using the `.upper()` method and then concatenates it with a space and the original string. Therefore, the output of this code would be "HELLO WORLD hello world".

    Rate this question:

  • 11. 

    Which two code segments output the number 20 to the console window?

    • A.

      MyValue01 = “10” myValue02 = “10” myValue01 = myValue01 + myValue02 print(myValue02)

    • B.

      MyValue01 = 10 myValue02 = 10 myValue01 = myValue01 + myValue02 print(myValue01)

    • C.

      MyValue01 = 10 myValue02 = 10 print(myValue01 + myValue02)

    • D.

      MyValue01 = “10” myValue02 = “10” print(myValue01 + myValue02)

    Correct Answer(s)
    B. MyValue01 = 10 myValue02 = 10 myValue01 = myValue01 + myValue02 print(myValue01)
    C. MyValue01 = 10 myValue02 = 10 print(myValue01 + myValue02)
    Explanation
    The first code segment assigns the value "10" to myValue01 and myValue02, then concatenates them and assigns the result to myValue01. Finally, it prints the value of myValue01, which is 20. The second code segment assigns the value 10 to myValue01 and myValue02, then adds them together and prints the result, which is also 20.

    Rate this question:

  • 12. 

    True or False: You can combine a numeric value and a string by using the + symbol. 

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The + symbol in programming is used for concatenation, which is the process of combining two strings together. It is not used to combine a numeric value and a string. To combine a numeric value and a string, you would need to convert the numeric value to a string first and then concatenate them. Therefore, the statement is false.

    Rate this question:

  • 13. 

    Which two operators can be used on numeric values in Python?

    • A.

      @

    • B.

      %

    • C.

      +

    • D.

      #

    Correct Answer(s)
    B. %
    C. +
    Explanation
    The % operator is used for modulus, which returns the remainder of a division operation. The + operator is used for addition, which adds two or more numeric values together. These two operators are commonly used in Python for performing mathematical operations on numeric values.

    Rate this question:

  • 14. 

    Given the numeric variable myNumber, which lines of code properly prints the value? (Select 2)

    • A.

      Print(“%d”)

    • B.

      Print(“%d”, myNumber)

    • C.

      Print(myNumber)

    • D.

      Print(“%d” % myNumber)

    Correct Answer(s)
    C. Print(myNumber)
    D. Print(“%d” % myNumber)
    Explanation
    The correct answer is "print(myNumber)" and "print("%d" % myNumber)". The first option prints the value of the variable directly, while the second option uses string formatting to insert the value of the variable into the string before printing it.

    Rate this question:

  • 15. 

     You have the following code segment: testValue = 2 testValue = 10 + (testValue * 2) What is the value of testValue?

    • A.

      10

    • B.

      12

    • C.

      14

    • D.

      2

    Correct Answer
    C. 14
    Explanation
    The code segment initializes the variable testValue with the value 2. Then, it assigns the result of the expression 10 + (testValue * 2) to testValue. Since testValue is currently 2, the expression evaluates to 10 + (2 * 2) = 10 + 4 = 14. Therefore, the value of testValue is 14.

    Rate this question:

  • 16. 

    Which two sections of code print 'Hello World' to the console?

    • A.

      MyValue = “Hello World” if myValue == “Hello World” : print(“Hello World”)

    • B.

      MyValue = “Hello World” if myValue == “Hello World” : print(myValue)

    • C.

      MyValue = “Hello World” if myValue != “Hello World” : print(myValue)

    • D.

      MyValue = “Hello World” if myValue != “Hello World” : print(“Hello World”)

    Correct Answer(s)
    A. MyValue = “Hello World” if myValue == “Hello World” : print(“Hello World”)
    B. MyValue = “Hello World” if myValue == “Hello World” : print(myValue)
    Explanation
    The two sections of code that print 'Hello World' to the console are:
    1. myValue = "Hello World"
    if myValue == "Hello World":
    print("Hello World")
    This section checks if myValue is equal to "Hello World" and if it is, it prints "Hello World" to the console.

    2. myValue = "Hello World"
    if myValue == "Hello World":
    print(myValue)
    This section also checks if myValue is equal to "Hello World" and if it is, it prints the value of myValue, which is "Hello World", to the console.

    Rate this question:

  • 17. 

    You have the following code segment: myValue = “yes” if myValue != “yes” :     print(“Hello”) print(“World”) What is the output from this code?

    • A.

      World Hello

    • B.

      Hello World

    • C.

      Hello

    • D.

      World

    Correct Answer
    D. World
    Explanation
    The output from this code is "World". The code assigns the value "yes" to the variable myValue. The if statement checks if myValue is not equal to "yes", which is false. Therefore, the print("Hello") statement is not executed. Finally, the print("World") statement is executed, resulting in the output "World".

    Rate this question:

  • 18. 

    You have the following code segment: currentAmount = 100 itemCost = 100 if currentAmount >= itemCost :     print(“Item Purchased”) else :     print(“Not Enough Funds”) What is the output from this code?

    • A.

      Not Enough Funds

    • B.

      Item Purchased Not Enough Funds

    • C.

      No output is displayed

    • D.

      Item Puchased

    Correct Answer
    D. Item Puchased
    Explanation
    The output from this code will be "Item Purchased". This is because the condition in the if statement is true, as the currentAmount is equal to the itemCost. Therefore, the code inside the if block will be executed, which is to print "Item Purchased".

    Rate this question:

  • 19. 

    Which symbol is used to check whether two variables are the same?

    • A.

      -

    • B.

      ==

    • C.

      |

    • D.

      =

    Correct Answer
    B. ==
    Explanation
    The symbol "==" is used to check whether two variables are the same. It is an equality operator that compares the values of the two variables and returns true if they are equal, and false otherwise.

    Rate this question:

  • 20. 

    Which code segment will NOT reach its print() function?

    • A.

      If ‘yes’ != ‘no’ : print(“condition met”)

    • B.

      If ‘yes’ != ‘yes’ : print(“condition met”)

    • C.

      If not ‘yes’ == ‘no’ : print(“condition met”)

    • D.

      If ‘yes’ == ‘yes’ : print(“condition met”)

    Correct Answer
    B. If ‘yes’ != ‘yes’ : print(“condition met”)
    Explanation
    The code segment "if 'yes' != 'yes' : print("condition met")" will not reach its print() function because the condition 'yes' != 'yes' is False, so the code block inside the if statement will not be executed.

    Rate this question:

  • 21. 

    Which line of code produces an error?

    • A.

      "7" + 'eight'

    • B.

      3 + 4

    • C.

      "one" + "2"

    • D.

      '5' + 6

    Correct Answer
    D. '5' + 6
    Explanation
    The line of code '5' + 6 produces an error because it is trying to concatenate a string ('5') with a number (6). In most programming languages, concatenating a string with a number is not allowed and results in a type mismatch error.

    Rate this question:

  • 22. 

    What is the output of this code? >>> print(3 * 'TCS') ANS = '_______'  

    Correct Answer
    TCSTCSTCS
    Explanation
    The code is using the multiplication operator (*) to repeat the string 'TCS' three times. Therefore, the output of the code will be 'TCSTCSTCS'.

    Rate this question:

  • 23. 

    What is the output of this code? >>> int("3" + "4")

    • A.

      "7"

    • B.

      "34"

    • C.

      34

    Correct Answer
    C. 34
    Explanation
    The code is concatenating the strings "3" and "4" using the + operator. Then, it is converting the resulting string "34" into an integer using the int() function. The int() function converts a string representation of a number into an actual integer. Therefore, the output of the code is the integer 34.

    Rate this question:

  • 24. 

    What is the output of this code? >>> float("210" * int(input("Enter a number:" ))) Enter a number: 2

    • A.

      "420.0"

    • B.

      "210210"

    • C.

      420

    • D.

      210210.0

    Correct Answer
    D. 210210.0
    Explanation
    The code first prompts the user to enter a number, which is then converted to an integer. The string "210" is then multiplied by this integer. The resulting string "210210" is then converted to a float, resulting in the output of "210210.0".

    Rate this question:

  • 25. 

    What is the output of this code? num = 7 if num > 3:    print("3")    if num < 5:       print("5")       if num ==7:         print("7")

    Correct Answer
    3
    Explanation
    The output of this code is "3". This is because the condition "num > 3" is true, so the code inside the if statement is executed. The next if statement "num < 5" is not executed because the condition is false. Finally, the last if statement "num == 7" is true, so the code inside is executed and "7" is printed. However, since there is no print statement for "5", it is not included in the output.

    Rate this question:

  • 26. 

    A shorter option for an "else if" statement is:

    Correct Answer
    elif
    Explanation
    The correct answer is "elif" because it is a shorter way to write "else if" in programming. It is used as a conditional statement to check for multiple conditions after an initial "if" statement. The "elif" statement allows for more concise and readable code by avoiding nested if statements.

    Rate this question:

  • 27. 

    What is the result of this code? if 1 + 1 * 3 == 6:    print("Yes") else:    print("No")

    • A.

      No

    • B.

      Yes

    Correct Answer
    A. No
    Explanation
    The result of this code is "No". This is because the condition in the if statement is false. The expression 1 + 1 * 3 evaluates to 4, not 6. Therefore, the code will execute the else block and print "No".

    Rate this question:

  • 28. 

    Which line of code will cause an error? num = [5, 4, 3, [2], 1] print(num[0]) print(num[3][0]) print(num[5])

    • A.

      Line 3

    • B.

      Line 2

    • C.

      Line 4

    Correct Answer
    C. Line 4
    Explanation
    Line 4 will cause an error because the index 5 is out of range for the list "num". The list "num" only has indices from 0 to 4.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 24, 2018
    Quiz Created by
    96redformy
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.