Exam 1 Flashcards
(38 cards)
What is wrong with the code snippet below?
print(Hello world)
Missing “ “ around Hello world
True or False: Python automatically inserts a newline character when you use the print command
True
Single line comment
#
Multiple line comment
’’’
What does the print statement do?
Sends your output to the screen
Which statement will print Hi! without a newline character?
print(“Hi!” , end= ‘ ‘)
How many arguments are in each of the following calls to the print function?
print(end= ‘ ‘)
print()
print(“Hi”,”there”)
print(“Hi there”)
print(“The quick brown fox” , “jumps” , “over the lazy” , “dog”, end= ‘\n’)
10215
True or False: the two names below refer to the same variable
My_Variable
my_variable
False
Declare the variable my_variable and assign it the value of “red” and assign another variable to overwrite this with “blue”
my_variable = “red”
my_variable = “blue”
What is the rule regarding boolean values in Python?
Boolean values in Python are case sensitive. They must start with a capital letter.
Strings
Collections of letters, numbers, and symbols
Boolean
True or False
Ints
Integers (no decimals)
Floats
Numbers with a decimal
Select the ways that a string can be declared
my_string = “I am a string”
my_string = “I am a string’
my_string = ‘“I am a string”’
my_string = ‘I am a string’
my_string = “I am a string”
my_string = ‘“I am a string”’
my_string = ‘I am a string’
What are the rules for variable names in Python?
You cannot use a keyword
The variable name must start with a letter or an underscore
The rest of the variable name can only be letters, numbers, or an underscore
Declare a variable my_boolean and assign it the boolean value of true. Print the variable
my_boolean = True
print(my_boolean)
Use two print statements to write the following string:
Okay, it is time to learn about operators
print(“Okay, “, end= ‘ ‘)
print(“it is time to learn about operators.”)
What happens when you add an int and a float?
You get a float
Select the line of code below that increments the variable by 1
a = a +1
In the following line of code, what value is stored in variable b when the program ends?
a = 5
b = 3
c = a + b
a = 2
b = c
8
True or False: The / operator sometimes returns an integer
False
True or False: The // operator always returns a whole number value
True
What does modulo do?
Returns the remainder after division is performed