Python Application Programming Quiz 1 : Klsvdit

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 Dr.RAMAKRISHNA
D
Dr.RAMAKRISHNA
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,525
Questions: 24 | Attempts: 1,525

SettingsSettingsSettings
Python Application Programming Quiz 1 : Klsvdit - Quiz


Questions and Answers
  • 1. 

    Write your text here

  • 2. 

    Write your text here

  • 3. 

    What is a correct syntax to output "Hello World" in Python?

    • A.

      Print("Hello World")

    • B.

      P("Hello World")

    • C.

      Echo "Hello World"

    • D.

      Echo("Hello World");

    Correct Answer
    A. Print("Hello World")
    Explanation
    The correct syntax to output "Hello World" in Python is "print("Hello World")". This statement uses the print function in Python to display the specified text on the console.

    Rate this question:

  • 4. 

    A string is immutable in Python? Every time when we modify the string, Python Always create a new String and assign a new string to that variable.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    In Python, strings are immutable, meaning that they cannot be changed once they are created. Whenever we modify a string, Python creates a new string and assigns it to a new variable, leaving the original string unchanged. This is why the statement "Every time when we modify the string, Python always creates a new string and assigns a new string to that variable" is true.

    Rate this question:

  • 5. 

    What is the output of the following code? var1 = 1 var2 = 2 var3 = "3" print(var + var2 + var3)

    • A.

      6

    • B.

      321

    • C.

      123

    • D.

      Error. Mixing operators between numbers and strings are not supported

    Correct Answer
    D. Error. Mixing operators between numbers and strings are not supported
    Explanation
    The code is attempting to concatenate a number and a string, which is not supported. This results in an error.

    Rate this question:

  • 6. 

    Which operator has higher precedence in the following list

    • A.

      **, Exponent

    • B.

      & BitWise AND

    • C.

      % Modulus

    • D.

      >< Comparison

    Correct Answer
    A. **, Exponent
    Explanation
    The ** operator, also known as the exponent operator, has higher precedence than the other operators in the given list. This means that any expression involving this operator will be evaluated before expressions involving the other operators.

    Rate this question:

  • 7. 

    What is the output of the following code? str = "pynative" print (str[1:3])

    • A.

      Py

    • B.

      Yn

    • C.

      Pyn

    • D.

      Yna

    Correct Answer
    B. Yn
    Explanation
    The code is using string slicing to extract a portion of the string "pynative". The slicing syntax [1:3] means that it will start from the character at index 1 (inclusive) and go up to, but not including, the character at index 3 (exclusive). Therefore, the output will be "yn", which is the substring starting from index 1 and ending at index 2 in the original string.

    Rate this question:

  • 8. 

    Which one is NOT a legal variable name?

    • A.

      _myvar

    • B.

      Myvar

    • C.

      My_var

    • D.

      My-var

    Correct Answer
    D. My-var
    Explanation
    The variable name "my-var" is not legal because it contains a hyphen. In most programming languages, hyphens are not allowed in variable names. Variables must typically consist of letters, numbers, and underscores, and they cannot start with a number. Therefore, "my-var" does not meet the criteria for a legal variable name.

    Rate this question:

  • 9. 

    What is the output of the following code? p, q, r = 10, 20 ,30 print(p, q, r)

    • A.

      10,20

    • B.

      Invalid syntax

    • C.

      10,20,30

    Correct Answer
    C. 10,20,30
    Explanation
    The given code assigns the values 10, 20, and 30 to the variables p, q, and r respectively. Then, it prints the values of p, q, and r which are 10, 20, and 30. Therefore, the output of the code is 10, 20, 30.

    Rate this question:

  • 10. 

    What is the output of the following x = 36 / 4 * (3 + 2) * 4 + 2 print(x)

    • A.

      182

    • B.

      The Program executed with errors

    • C.

      37

    • D.

      117

    Correct Answer
    A. 182
    Explanation
    The correct answer is 182. This is because the expression follows the order of operations, which states that parentheses should be evaluated first, followed by multiplication and division from left to right, and finally addition and subtraction from left to right. In this case, the expression inside the parentheses, (3 + 2), evaluates to 5. Then, the division 36 / 4 is performed, resulting in 9. Next, the multiplication 9 * 5 * 4 is done, giving 180. Finally, the addition 180 + 2 is calculated, resulting in the final output of 182.

    Rate this question:

  • 11. 

    Var = "KLS" * 2 * 3 print(var)

    • A.

      KLSKLSKLSKLSKLSKLS

    • B.

      Syntax Error

    • C.

      KLSKLS

    • D.

      KLSKLSKLS

    Correct Answer
    A. KLSKLSKLSKLSKLSKLS
    Explanation
    The given code assigns the string "KLS" to the variable "var" and then multiplies it by 2 and 3. This means that the string "KLS" is repeated 2 times and then the resulting string is repeated 3 times. The final output is "KLSKLSKLSKLSKLSKLS".

    Rate this question:

  • 12. 

    Can we use the “else” clause for loops? for example: for i in range(1, 5): print(i) else: print("this is else block statement" )

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
    Explanation
    Yes, we can use the "else" clause for loops. In this example, the loop iterates over the range from 1 to 5. After the loop completes all iterations, the "else" block is executed, and the statement "this is else block statement" is printed. The "else" clause in a loop is executed only if the loop completes all iterations without encountering a "break" statement.

    Rate this question:

  • 13. 

    What is the output of the following code? listOne = [20, 40, 60, 80] listTwo = [20, 40, 60, 80] print(listOne == listTwo) print(listOne is listTwo)

    • A.

      True True

    • B.

      True False

    • C.

      False True

    • D.

      False False

    Correct Answer
    B. True False
    Explanation
    The output of the code is "True" and "False". The first print statement compares the values of the two lists, so it returns True because the values in both lists are the same. The second print statement uses the "is" operator to check if the two lists are the same object in memory, which is not the case here, so it returns False.

    Rate this question:

  • 14. 

    How do you create a variable with the floating number 2.8?

    • A.

      X = float(2.8)

    • B.

      X =2.8

    • C.

      Both the other answers are correct

    Correct Answer
    C. Both the other answers are correct
    Explanation
    The correct answer is that both the other answers are correct. This means that you can create a variable with the floating number 2.8 by either using the float() function or directly assigning the value 2.8 to the variable. Both methods will result in the variable holding the floating number 2.8.

    Rate this question:

  • 15. 

    What is the correct syntax to output the type of a variable or object in Python?

    • A.

      Print(type(x))

    • B.

      Print(typeof x)

    • C.

      Print(typeof(x))

    • D.

      Print(typeOf(x))

    Correct Answer
    A. Print(type(x))
    Explanation
    The correct syntax to output the type of a variable or object in Python is "print(type(x))". This will print the type of the variable or object stored in the variable "x".

    Rate this question:

  • 16. 

    What is the correct way to create a function in Python?

    • A.

      Function myfunction():

    • B.

      Create myFunction():

    • C.

      Def myFunction():

    Correct Answer
    C. Def myFunction():
    Explanation
    The correct way to create a function in Python is by using the "def" keyword followed by the function name and parentheses. This is the standard syntax for defining a function in Python.

    Rate this question:

  • 17. 

    What is a correct syntax to return the first character in a string?

    • A.

      X = sub("Hello", 0, 1)

    • B.

      X = "Hello"[0]

    • C.

      X = "Hello".sub(0, 1)

    Correct Answer
    B. X = "Hello"[0]
    Explanation
    The correct syntax to return the first character in a string is "x = "Hello"[0]". This syntax uses indexing to access the first character of the string "Hello". The index 0 represents the first character in the string.

    Rate this question:

  • 18. 

    Which method can be used to return a string in upper case letters?

    • A.

      Upper()

    • B.

      Toupper()

    • C.

      Uppercase()

    • D.

      UpperCase()

    Correct Answer
    A. Upper()
    Explanation
    The correct answer is "upper()". This method can be used to return a string in upper case letters.

    Rate this question:

  • 19. 

    Which method can be used to replace parts of a string?

    • A.

      Repl()

    • B.

      Replace()  

    • C.

      ReplaceString()

    • D.

      Switch()

    Correct Answer
    B. Replace()  
    Explanation
    The method "replace()" can be used to replace parts of a string. This method takes two parameters: the substring to be replaced and the substring to replace it with. It searches for all occurrences of the substring in the given string and replaces them with the new substring. This method is commonly used for tasks such as replacing certain characters or words within a string.

    Rate this question:

  • 20. 

    Which of these collections defines a LIST?

    • A.

      ("apple", "banana", "cherry")  

    • B.

      {"name": "apple", "color": "green"}

    • C.

      {"apple", "banana", "cherry"}

    • D.

      ["apple", "banana", "cherry"]  

    Correct Answer
    D. ["apple", "banana", "cherry"]  
    Explanation
    The correct answer is [ "apple", "banana", "cherry" ] because it is enclosed in square brackets, which is the syntax for defining a list in many programming languages. Lists are ordered collections of items, and in this case, the list contains three strings: "apple", "banana", and "cherry". The other options are not valid syntax for defining a list.

    Rate this question:

  • 21. 

    Which of these collections defines a TUPLE?

    • A.

      ("apple", "banana", "cherry")  

    • B.

      ["apple", "banana", "cherry"]

    • C.

      {"apple", "banana", "cherry"}

    • D.

      {name: "apple", "banana", "cherry"}

    Correct Answer
    A. ("apple", "banana", "cherry")  
    Explanation
    A tuple is defined by using parentheses, as shown in the correct answer. The other options use square brackets, curly braces, or a combination of curly braces and colons, which are not the correct syntax for defining a tuple.

    Rate this question:

  • 22. 

    Which of these collections defines a SET?

    • A.

      {name: "apple", "banana", "cherry"}  

    • B.

      ("apple", "banana", "cherry")

    • C.

      ["apple", "banana", "cherry"] 

    • D.

      {"apple", "banana", "cherry"}  

    Correct Answer
    D. {"apple", "banana", "cherry"}  
    Explanation
    The correct answer is {"apple", "banana", "cherry"}. This is because a set is an unordered collection of unique elements, and the given collection only contains unique elements and is enclosed in curly braces, which is the syntax for defining a set in many programming languages. The other options either contain duplicate elements or use different syntax, making them incorrect.

    Rate this question:

  • 23. 

    Which collection is ordered, changeable, and allows duplicate members?

    • A.

      LIST

    • B.

      SET

    • C.

      DICTIONARY

    • D.

      TUPLE

    Correct Answer
    A. LIST
    Explanation
    A list is an ordered collection in Python that allows duplicate elements and is changeable, meaning that elements can be added, removed, or modified. This makes it the correct answer for the given question. Sets, dictionaries, and tuples have different characteristics and do not meet all the requirements mentioned in the question.

    Rate this question:

  • 24. 

    How do you start writing an if statement in Python?

    • A.

      If x > y then:

    • B.

      If x > y:

    • C.

      If (x > y)

    Correct Answer
    B. If x > y:
    Explanation
    The correct answer is "if x > y:". In Python, an if statement is started by using the keyword "if" followed by the condition that needs to be evaluated. The condition in this case is "x > y", which checks if the value of x is greater than the value of y. The colon at the end of the line indicates the start of the code block that will be executed if the condition is true.

    Rate this question:

  • 25. 

    Which statement is used to stop a loop?

    • A.

      Exit

    • B.

      Break

    • C.

      Stop

    • D.

      Return

    Correct Answer
    B. Break
    Explanation
    The correct answer is "break". In programming, the "break" statement is used to terminate a loop prematurely. When the "break" statement is encountered within a loop, the loop is immediately exited, and the program continues executing from the next line after the loop. This is useful when a certain condition is met, and you want to stop the loop from further iterations.

    Rate this question:

  • 26. 

    What is the output of the following code salary = 8000 def printSalary(): salary = 12000 print("Salary:", salary) printSalary(); print("Salary:", salary)

    • A.

      Salary: 8000 Salary: 12000

    • B.

      Salary: 12000 Salary: 8000

    • C.

      Errors

    Correct Answer
    B. Salary: 12000 Salary: 8000
    Explanation
    The code defines a variable "salary" with a value of 8000. Then, a function "printSalary()" is defined, which creates a new variable "salary" with a value of 12000 and prints it. When the function is called, it prints "Salary: 12000". After that, outside of the function, the original variable "salary" with a value of 8000 is printed, resulting in "Salary: 8000". Therefore, the output of the code is "Salary: 12000 Salary: 8000".

    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 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 24, 2020
    Quiz Created by
    Dr.RAMAKRISHNA
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.