Computer Science Python Test

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 Athornsburg
A
Athornsburg
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,069
Questions: 30 | Attempts: 1,126

SettingsSettingsSettings
Computer Science Python Test - Quiz


This test covers the first four introductory chapters on Python programming.


Questions and Answers
  • 1. 

    The following codes all have one error.  In your answer describe the problem and how to fix it.  (5 PTS each)

  • 2. 

    #NiceSquareSpiral.pyimport turtle   colors=['red', 'purple', 'blue',        'green', 'yellow', 'orange']t=turtle.pen()t.speed(0)turtle.bgcolor('black')for x in range(360):    t.pencolor(colors[x%4])    t.width(x/100+1)    t.forward(x)            t.left(88)

  • 3. 

    Import turtlet = turtle.Pen()turtle.bgcolor("black")t.speed(0)sides = 3colors = ["red", "yellow", "blue", "orange", "green", "purple"]for x in range(360):t.pencolor(colors[x%sides])t.forward(x * 3 / sides + x)t.left(360/sides + 1)t.width(x*sides/100)

  • 4. 

    SquareSpiral1.pyimport turtlet = turtle.Pen()t.speed(0)for x in range(100):    t.forward(2*x)    t.left(90)

  • 5. 

    # AtlantaPizza.py # Ask the person how many pizzas they want, get the number with eval()number_of_pizzas = eval(input("How many pizzas do you want? ")) # Ask for the menu cost of each pizzacost_per_pizza = eval(input("How much does each pizza cost? ") # Calculate the total cost of the pizzas as our subtotalsubtotal = number_of_pizzas * cost_per_pizza # Calculate the sales tax owed, at 8% of the subtotaltax_rate = 0.08     # Store 8% as the decimal value 0.08sales_tax = subtotal * tax_rate # Add the sales tax to the subtotal for the final totaltotal = subtotal + sales_tax # Show the user the total amount due, including taxprint("The total cost is $", total)print("This includes $", subtotal, "for the pizza and")print("$", sales_tax, "in sales tax.")

  • 6. 

    # SayOurNames.py - lets everybody print their name on the screen# Ask the user for their namename = input("What is your name? ")# Keep printing names until we want to quitwhile name != "":    # Print their name 100 times    for x in range(100):    # Print their name followed by a space, not a new line    print(name, end = " ")    print()   # After the for loop, skip down to the next line    # Ask for another name, or quit    name = input("Type another name, or just hit [ENTER] to quit: ")print("Thanks for playing!")

  • 7. 

    Answer the following multiple choice questions. (2PT)

  • 8. 

    What program do you run to enter the Python editor?

    • A.

      Windows

    • B.

      Python

    • C.

      Idle

    • D.

      Interactive Mode

    Correct Answer
    C. Idle
    Explanation
    Idle is the correct answer because it is a popular integrated development environment (IDE) for Python programming. It provides a user-friendly interface and various features such as syntax highlighting, code completion, and debugging tools. By running Idle, users can easily enter the Python editor and start writing and executing their Python code.

    Rate this question:

  • 9. 

    The >>> symbol in Python is known as the _______.

    • A.

      Prompt

    • B.

      Cursor

    • C.

      Whack

    • D.

      Float

    Correct Answer
    A. Prompt
    Explanation
    The ">>>" symbol in Python is known as the prompt. It is used to indicate that the Python interpreter is ready to receive input from the user.

    Rate this question:

  • 10. 

    Within Python, there are two different modes.  Which mode is instant and runs a line of code the second the user presses 'enter'?

    • A.

      Editor

    • B.

      Shell

    • C.

      Loop

    • D.

      Interactive mode

    Correct Answer
    D. Interactive mode
    Explanation
    Interactive mode within Python allows the user to enter and execute code immediately after pressing 'enter'. It provides a way to interactively experiment with code and see the results instantly. This mode is particularly useful for quick testing and debugging purposes.

    Rate this question:

  • 11. 

    What file extension do all files created in Python end in?  (Example: an audio file might end in a FLAC or MP3 file extension)

    • A.

      EXE

    • B.

      BAT

    • C.

      PY

    • D.

      DLL

    Correct Answer
    C. PY
    Explanation
    All files created in Python end with the file extension ".py". This is the standard file extension for Python source code files. It helps to identify and differentiate Python files from other types of files.

    Rate this question:

  • 12. 

    While coding, programmers often make notes to themselves or other programmers.  These notes left behind by programmers are called comments.  When adding a comment, what symbol must the programmer add to tell Python to overlook this line in the code?

    • A.

      #

    • B.

      >>>>

    • C.

      ()

    • D.

      []

    Correct Answer
    A. #
    Explanation
    In Python, the symbol # is used to add comments in the code. When a programmer adds a # symbol before a line of code, Python overlooks that line and does not execute it as part of the program. This allows programmers to add notes or explanations within the code without affecting its functionality.

    Rate this question:

  • 13. 

    "Reserved words" in Python are also known as _______.  These words and reserved by Python for particular functions.  When these words are typed they change to a different color in the code.

    • A.

      Shortcuts

    • B.

      Index

    • C.

      Variables

    • D.

      Keywords

    Correct Answer
    D. Keywords
    Explanation
    Keywords in Python are reserved words that have a specific meaning and purpose in the language. These words are predefined and cannot be used as variable names or any other identifiers. When these keywords are typed in a Python code, they are recognized by the Python interpreter and are displayed in a different color to distinguish them from other parts of the code.

    Rate this question:

  • 14. 

    Turtle is a _________ built into Python that performs drawing functions.

    • A.

      Program

    • B.

      Command

    • C.

      Module

    • D.

      Keyword

    Correct Answer
    C. Module
    Explanation
    A module is a built-in feature in Python that allows for the organization and reuse of code. It contains functions, variables, and classes that can be imported and used in other Python programs. In this context, the turtle module in Python provides a set of drawing functions that can be used to create graphics and animations. Therefore, the correct answer is "Module".

    Rate this question:

  • 15. 

    If a programmer wishes to use Turtle, what line of code should they first type to enable it?

    • A.

      T = turtle

    • B.

      Import turtle

    • C.

      Turtle

    • D.

      Turtle.Pen

    Correct Answer
    B. Import turtle
    Explanation
    The correct answer is "import turtle". This line of code is used to import the turtle module in Python, which allows the programmer to use Turtle graphics. By importing the turtle module, the programmer gains access to various functions and methods that can be used to create and manipulate turtle graphics on the screen.

    Rate this question:

  • 16. 

    In the following statement identify the variable.t = turtle.Pen

    • A.

      T

    • B.

      =

    • C.

      Turtle.Pen

    • D.

      ""

    Correct Answer
    A. T
    Explanation
    The given statement assigns the value of turtle.Pen to the variable t. This means that the variable t now represents the turtle pen object, allowing us to use t to access the various methods and attributes associated with the turtle pen.

    Rate this question:

  • 17. 

    What is a value?

    • A.

      A type that represents sequences of characters.

    • B.

      One of the basic units of data, like a number or string, that a program manipulates.

    • C.

      A program stored in a file (usually one that will be interpreted).

    • D.

      The structure of a program.

    Correct Answer
    B. One of the basic units of data, like a number or string, that a program manipulates.
    Explanation
    A value is one of the basic units of data that a program can manipulate. It can be a number or a string, and it is used to store and represent information within a program. Values can be assigned to variables and used in calculations or operations to perform tasks and produce desired results.

    Rate this question:

  • 18. 

    What is a string?

    • A.

      A category of values. The types we have seen so far are integers (type int), floatingpoint numbers (type float), and strings (type str).

    • B.

      A programming statement that allows a block of code to be repeated as long as a condition is true.

    • C.

      A sequence of characters, which can include letters, numbers, symbols, punctuation, and spacing.

    • D.

      A named value that can change

    Correct Answer
    C. A sequence of characters, which can include letters, numbers, symbols, punctuation, and spacing.
    Explanation
    A string is a sequence of characters that can include letters, numbers, symbols, punctuation, and spacing. It is a data type in programming used to store and manipulate textual data. Strings are commonly used for representing words, sentences, and any other textual information in computer programs.

    Rate this question:

  • 19. 

    What is a loop?

    • A.

      A part of a program that can execute repeatedly.

    • B.

      A file or set of files with related variables, functions, and classes that can be reused in other programs.

    • C.

      A symbol or set of symbols that represents an action or comparison and returns a result, such as +, -, *, //, , ==, and so on.

    • D.

      An input variable to a function, specified in the function’s definition

    Correct Answer
    A. A part of a program that can execute repeatedly.
    Explanation
    A loop is a control structure in programming that allows a certain set of instructions to be repeated multiple times. It is a mechanism that enables a part of a program to execute repeatedly until a specific condition is met. This allows for efficient and concise coding, as repetitive tasks can be automated using loops.

    Rate this question:

  • 20. 

    What is an operator?

    • A.

      A variable containing information about a single instance of a class, such as a single sprite from the Sprite class.

    • B.

      A special, reserved word that means something in a particular programming language.

    • C.

      An input variable to a function, specified in the function’s definition.

    • D.

      A symbol or set of symbols that represents an action or comparison and returns a result, such as +, -, *, //, , ==.

    Correct Answer
    D. A symbol or set of symbols that represents an action or comparison and returns a result, such as +, -, *, //, , ==.
    Explanation
    An operator is a symbol or set of symbols that represents an action or comparison and returns a result. In programming, operators are used to perform mathematical calculations, manipulate data, or compare values. Examples of operators include + (addition), - (subtraction), * (multiplication), / (division), // (floor division), % (modulus), and == (equality comparison). These operators allow programmers to perform various operations and make decisions based on the results.

    Rate this question:

  • 21. 

    The values the operator is applied to are called _____.

    • A.

      Intergers

    • B.

      Types

    • C.

      Operands

    • D.

      Variables

    Correct Answer
    C. Operands
    Explanation
    The term "operands" refers to the values that an operator is applied to in an expression. In this context, the question is asking for the specific term that is used to describe these values. "Integers," "types," and "variables" are not the correct terms to describe the values that an operator operates on.

    Rate this question:

  • 22. 

    When giving a value to a variable it is known as a ________.

    • A.

      Script

    • B.

      Assignment statement

    • C.

      Semantics

    • D.

      Parse

    Correct Answer
    B. Assignment statement
    Explanation
    An assignment statement is used to give a value to a variable. It is a fundamental concept in programming, where a variable is assigned a specific value or expression. This allows the variable to store and manipulate data throughout the program. The other options, such as script, semantics, and parse, are not directly related to the act of giving a value to a variable.

    Rate this question:

  • 23. 

    ("What is your name?") is a _________.

    • A.

      String

    • B.

      Loop

    • C.

      Operator

    • D.

      Variable

    Correct Answer
    A. String
    Explanation
    The given correct answer for this question is "String" because the phrase "What is your name?" is a sequence of characters, which is the definition of a string in computer programming. In this context, it represents a piece of text or a sentence rather than a mathematical operation, a repeated action, or a container for holding a value.

    Rate this question:

  • 24. 

    [] indicates a _____.

    • A.

      Loop

    • B.

      String

    • C.

      Value

    • D.

      List

    Correct Answer
    D. List
    Explanation
    The given correct answer is "List" because the brackets [] are commonly used to represent a list in many programming languages. A list is a data structure that can hold multiple values and allows for easy access and manipulation of those values. Therefore, the brackets in this context indicate a list.

    Rate this question:

  • 25. 

    A whole number such as 6 is seen in Python as what type?

    • A.

      String

    • B.

      Float

    • C.

      Interger

    • D.

      Operand

    Correct Answer
    C. Interger
    Explanation
    The given correct answer is "Interger". In Python, a whole number like 6 is considered as an integer data type. Integers are used to represent whole numbers without any decimal points. They can be positive, negative, or zero.

    Rate this question:

  • 26. 

    The number 3.5 is seen in Python as this type:

    • A.

      String

    • B.

      Float

    • C.

      Interger

    • D.

      Operand

    Correct Answer
    B. Float
    Explanation
    The number 3.5 is seen in Python as a Float. Float is a data type in Python that represents decimal or floating-point numbers, which can have both an integer and a fractional part.

    Rate this question:

  • 27. 

    This type of loop runs for a set length or range.

    • A.

      For

    • B.

      While

    • C.

      If

    • D.

      Nested

    Correct Answer
    A. For
    Explanation
    The correct answer is "For". A for loop is used when we know the number of iterations that need to be executed beforehand. It runs for a set length or range, as specified in the loop statement. The loop variable is initialized, condition is checked, and the loop body is executed until the condition becomes false or the specified range is reached. This makes the for loop suitable for iterating over arrays, lists, or any other data structure with a known length.

    Rate this question:

  • 28. 

    This type of loop runs inside of another loop.

    • A.

      For

    • B.

      While

    • C.

      Nested

    • D.

      If

    Correct Answer
    C. Nested
    Explanation
    A nested loop is a loop that is present inside another loop. It allows the execution of a set of statements repeatedly within the outer loop. This type of loop is useful when we need to perform a certain action multiple times, and each time it needs to be repeated a specific number of times. By using a nested loop, we can control the flow of execution and achieve the desired outcome.

    Rate this question:

  • 29. 

    This loop, also known as the game loop, runs until a condition is met.

    • A.

      For

    • B.

      While

    • C.

      Nested

    • D.

      If

    Correct Answer
    B. While
    Explanation
    The correct answer is "While". In programming, a while loop is used to repeatedly execute a block of code as long as a certain condition is true. It is commonly used as a game loop, where the loop continues running until a specific condition or event occurs. The while loop evaluates the condition before each iteration, and if the condition is true, the loop continues. Once the condition becomes false, the loop terminates, and the program moves on to the next line of code.

    Rate this question:

  • 30. 

    This type of error message occurs when a command is miss-typed.

    • A.

      Runtime error

    • B.

      Semantic Error

    • C.

      Compiler Error

    • D.

      Syntax Error

    Correct Answer
    D. Syntax Error
    Explanation
    A syntax error occurs when a command is miss-typed or written in a way that does not follow the correct syntax rules of the programming language. This means that the code is not written in a way that the compiler or interpreter can understand and execute. Syntax errors are usually detected by the compiler or interpreter during the compilation or execution process, and they prevent the program from running properly.

    Rate this question:

  • 31. 

    In the range 0-10, what numbers are being counted?

    • A.

      1-10

    • B.

      0-9

    • C.

      0-10

    • D.

      John Cena

    Correct Answer
    B. 0-9
    Explanation
    The correct answer is 0-9 because the question asks for the numbers being counted in the range 0-10. However, since the range is specified as 0-10, it means that both the starting and ending numbers are included. Therefore, the numbers being counted in this range are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

    Rate this question:

  • 32. 

    What is the purpose of the eval() function?

    • A.

      A set of instructions that is repeated until a condition is reached.

    • B.

      A sequence of characters, which can include letters, numbers, symbols, punctuation, and spacing

    • C.

      The spelling and grammar rules of a programming language.

    • D.

      Figures out the value within a string

    Correct Answer
    D. Figures out the value within a string
    Explanation
    The purpose of the eval() function is to figure out the value within a string. This function takes a string as input and evaluates it as a Python expression. It can be used to execute dynamically created code or to perform mathematical calculations stored as strings. The eval() function is commonly used when working with user input or when dealing with dynamic code execution.

    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
  • Dec 04, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 25, 2015
    Quiz Created by
    Athornsburg
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.