D335 Introduction to Python Test Quizzes with
Answers Verified 100% Correct
What is an expression?
Expressions are any code that return a value when it is evaluated by the program; for example,
the code "5 + 6" is an expression that computes a number by adding two values.
A new variable is created by
performing an assignment statement using the = symbol, such as favoritecolor = red
What character denotes comments in Python?
The character '#' denotes comments
For example:
# this is a comment
How do you print text to the screen in Python?
The primary way to print output is to use the built-in function print(). Ex: print('hello world').
What is text enclosed in quotes called?
A string literal.
What is good practice when writing string literals?
Good practice is to use single quotes for shorter strings and double quotes for more
complicated text or text that contains single quotes, like print("Don't eat that!").
How can output with the print() function be moved to a new line?
Output can be moved to the next line by including "\n" in your string, which is known as
a newline character.
Ex: print('1\n2\n3')
, This will print "1" on the first line, "2" on the second line, and "3" on the third line of output.
"\n" consists of two characters, \ and n, but together are considered by the Python
interpreter as a single character.
What function does Python use to read input from a user?
Reading input is achieved using the input() function.
Does print() automatically add a new line character after it outputs a string?
Yes / True
print() always adds a newline character after the output and automatically moves the
next output to the next row.
How do you keep a print() function from creating a new line?
Use end=' ' inside of the print() function after your string (separated by a comma).
e.g:
print('My name is...', end=' ')
print('Carl?')
What is a SyntaxError?
The program contains invalid code that cannot be understood.
What is a IndentationError?
The lines of the program are not properly indented.
What is a ValueError?
An invalid value is used.
This can occur if giving letters to int().
What is a NameError?
Answers Verified 100% Correct
What is an expression?
Expressions are any code that return a value when it is evaluated by the program; for example,
the code "5 + 6" is an expression that computes a number by adding two values.
A new variable is created by
performing an assignment statement using the = symbol, such as favoritecolor = red
What character denotes comments in Python?
The character '#' denotes comments
For example:
# this is a comment
How do you print text to the screen in Python?
The primary way to print output is to use the built-in function print(). Ex: print('hello world').
What is text enclosed in quotes called?
A string literal.
What is good practice when writing string literals?
Good practice is to use single quotes for shorter strings and double quotes for more
complicated text or text that contains single quotes, like print("Don't eat that!").
How can output with the print() function be moved to a new line?
Output can be moved to the next line by including "\n" in your string, which is known as
a newline character.
Ex: print('1\n2\n3')
, This will print "1" on the first line, "2" on the second line, and "3" on the third line of output.
"\n" consists of two characters, \ and n, but together are considered by the Python
interpreter as a single character.
What function does Python use to read input from a user?
Reading input is achieved using the input() function.
Does print() automatically add a new line character after it outputs a string?
Yes / True
print() always adds a newline character after the output and automatically moves the
next output to the next row.
How do you keep a print() function from creating a new line?
Use end=' ' inside of the print() function after your string (separated by a comma).
e.g:
print('My name is...', end=' ')
print('Carl?')
What is a SyntaxError?
The program contains invalid code that cannot be understood.
What is a IndentationError?
The lines of the program are not properly indented.
What is a ValueError?
An invalid value is used.
This can occur if giving letters to int().
What is a NameError?