0% found this document useful (0 votes)
54 views

Python Quiz 1 Retake

The document is a quiz on Python concepts with multiple choice questions and explanations for each answer. It covers topics like variables, data types, functions, conditionals, loops, and more.

Uploaded by

Kiefer Zhang
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Python Quiz 1 Retake

The document is a quiz on Python concepts with multiple choice questions and explanations for each answer. It covers topics like variables, data types, functions, conditionals, loops, and more.

Uploaded by

Kiefer Zhang
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Quiz Retake (Open resource)

Name: Kiefer

Please (1) retake the quiz and (2) explain why the answer you chose is correct.
Highlight the correct answer. Any copy/pasting or plagiarism will result in a 0.

1. What is the role of a variable in Python?


a) Display information
b) Store and manipulate data
c) Define functions
d) Create loops
Explain: B: A programmer uses variables to store data so that it can be referenced or used for
later in the program.

2. How do you assign a value to a variable in Python?


a) set x = 5
b) x = 5
c) 5 to x
d) value(x) = 5
Explain: B, because the = sign signify storing of info into the variable

3. What is a function in Python?


a) A reserved word
b) A data type
c) A reusable block of code
d) A loop statement
Explain. wC, a function is a block of reusable code that is able to tell python to do specific tasks.

4. What is a constant in Python?


a) A variable that cannot be changed
b) A reserved keyword
c) A data type
d) A loop structure
Explain. A, a constant is a variable that is unable to be changed or altered in the program

5. How do you print the value of a variable in Python?


a) show(x)
b) output x
c) print(x)
d) display(x)
Explain. C, the code “print” tells python to print the value that has been set to the variable x.

6. How can you get user input in Python?


a) input()
b) get_input()
c) user()
d) read_input()
Explain: A, by using code “input” the program pause and asks the user for an input.

7. Which of the following is not a basic data type in Python?


a) int
b) float
c) array
d) str
Explain. C, array is a more complicated variable which can hold multiple variables at one time.

8. What is the purpose of an if statement in Python?


a) To create a loop
b) To define a function
c) To make decisions
d) To print output
Explain. C: if statements purpose is to give the users a choice like if A was true python would do
a certain task but if A isn’t true then python would skip it or do something else.

9. What does a for loop do in Python?


a) Repeats a block of code a specific number of times
b) Executes code as long as a condition is true
c) Defines a function
d) Prints output to the console
Explain A, a loop’s purpose in coding is to repeat the same line of code a specific amount of
times.

10. What is the Python interactive shell used for?


a) Writing and running scripts
b) Interacting with the operating system
c) Experimenting with Python code line by line
d) Creating graphical user interfaces (GUIs):
Explain C, Python isn’t able to run long blocks of code so the primary use of Python’s interactive
shell is to experiment with the Python code line by line.

11. What is a valid Python variable name?


a) 123variable
b) my-variable
c) _my_variable
d) variable@name
Explain. C, because a valid Python variable name needs to start with either letter or underscore,
can’t start with number or signs like #, and it needs to be case sensitive.

12. What does the term "mnemonic variable" refer to in Python?


a) A variable that uses a single character as its name.
b) A variable name that serves as a memory aid to convey its meaning or purpose.
c) A variable with a name that is difficult to remember.
d) A reserved keyword for defining variables.
Explain B, a mnemonic variable purpose to help us remember why we made the variable in the
first place

13. In Python, what is the primary purpose of the '#' symbol?


a) To denote the beginning of a Python script.
b) To indicate the end of a Python statement.
c) To represent a mathematical operation, such as exponentiation.
d) To signify the start of a comment in Python code.
Explain. B, the # symbol is to tell Python to ignore the rest of the line of code.

14. What is the primary difference between the Python shell and a text editor?
a) The Python shell is used for writing and saving Python code files, while a text editor is
used for executing Python code.
b) The Python shell is an interface for interacting with Python code in real-time, while a
text editor is used for writing and saving longer Python code files.
c) The Python shell is a type of text editor specifically designed for Python programming.
d) The Python shell and a text editor serve the same purpose and can be used
interchangeably.
Explain. B, The Python shell allows us to interact with the code in real time because it would
instantly give out the result whereas the text editor is used to write and save longer bars of
code.

You might also like