WGU D335 Intro to Python – Comprehensive
Practice Exam
1. A named item used to hold a value in a program is called a:
a) Function
b) Variable
c) Loop
d) Operator
CORRECT ANSWER: b) Variable
2. Which of the following is a correct way to create a comment in Python?
a) `// This is a comment`
b) `<! This is a comment `
c) `# This is a comment`
d) `/* This is a comment */`
CORRECT ANSWER: c) `# This is a comment`
3. What is the data type of `x` after the assignment `x = 5.0`?
a) int
b) float
,c) str
d) bool
CORRECT ANSWER: b) float
4. What is the output of `print(3 + 2.5)`?
a) 5
b) 5.5
c) 6
d) Error
CORRECT ANSWER: b) 5.5 (Python performs implicit type conversion)
5. Which function is used to get text input from a user?
a) `print()`
b) `get()`
c) `input()`
d) `scan()`
CORRECT ANSWER: c) `input()`
6. To convert a string like `"123"` into an integer, you would use:
a) `string()`
b) `int()`
c) `float()`
, d) `str()`
CORRECT ANSWER: b) `int()`
7. Which of the following is NOT a valid variable name in Python?
a) `my_var`
b) `_myvar`
c) `2myvar`
d) `myVar2`
CORRECT ANSWER: c) `2myvar` (Variable names cannot start with a number)
8. What does the `type()` function do?
a) Changes the data type of a variable.
b) Deletes a variable.
c) Returns the data type of a value or variable.
d) Creates a new type of variable.
CORRECT ANSWER: c) Returns the data type of a value or variable.
9. If you want to keep multiple `print()` statements on the same line, you use:
a) `sep=' '`
b) `end=' '`
c) `line=' '`
d) `\n`
Practice Exam
1. A named item used to hold a value in a program is called a:
a) Function
b) Variable
c) Loop
d) Operator
CORRECT ANSWER: b) Variable
2. Which of the following is a correct way to create a comment in Python?
a) `// This is a comment`
b) `<! This is a comment `
c) `# This is a comment`
d) `/* This is a comment */`
CORRECT ANSWER: c) `# This is a comment`
3. What is the data type of `x` after the assignment `x = 5.0`?
a) int
b) float
,c) str
d) bool
CORRECT ANSWER: b) float
4. What is the output of `print(3 + 2.5)`?
a) 5
b) 5.5
c) 6
d) Error
CORRECT ANSWER: b) 5.5 (Python performs implicit type conversion)
5. Which function is used to get text input from a user?
a) `print()`
b) `get()`
c) `input()`
d) `scan()`
CORRECT ANSWER: c) `input()`
6. To convert a string like `"123"` into an integer, you would use:
a) `string()`
b) `int()`
c) `float()`
, d) `str()`
CORRECT ANSWER: b) `int()`
7. Which of the following is NOT a valid variable name in Python?
a) `my_var`
b) `_myvar`
c) `2myvar`
d) `myVar2`
CORRECT ANSWER: c) `2myvar` (Variable names cannot start with a number)
8. What does the `type()` function do?
a) Changes the data type of a variable.
b) Deletes a variable.
c) Returns the data type of a value or variable.
d) Creates a new type of variable.
CORRECT ANSWER: c) Returns the data type of a value or variable.
9. If you want to keep multiple `print()` statements on the same line, you use:
a) `sep=' '`
b) `end=' '`
c) `line=' '`
d) `\n`