lis4369 Exam 1
Joel
Given the following list, what is the value of names[2]? names = ["Lizzy", "Mike", "Joel", "Anne", "Donald Duck"] Mike
IDLE's editor
To create a Python program, you use:
break statement
To jump to the end of the current loop, you can use the
the F5 key
To run a Python program from IDLE, you use:
IDLE's interactive shell
To test a Python statement, you use:
"My student ID is " + str(123456)
What is the argument of the print() function in the following Python statement? print("My student ID is " + str(123456))
nothing will display
What will be displayed after the following code executes? guess = 19 if guess < 19: print("Too low") elif guess > 19: print("Too high")
the program crashes and an error message is displayed
When an exception occurs while a program is running,
sort sequence
When two strings are compared, they are evaluated based on the ___________________ of the characters in the string.
import the module
Before you can use a standard module like the random module, you need to
via a command prompt
A console application runs
module
A file that contains reusable code is called a
once for each integer in the collection returned by the range() function
A for loop that uses a range() function is executed
is defined outside of all functions
A global variable
inside a function
A local variable is defined
can be used to return a local variable to the calling function
A return statement
an exception
A runtime error is also known as:
a browser
A web application runs through
main()
Consider the following code: def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) if __name__ == "__main__": main()
6
How many times will "Hi again!" be displayed after the following code executes? for i in range(0, 12, 2): print("Hi, again!")
change line 4 to: print("The discount on this item is $", round(discount, 2))
Given the following code and its output: discount_rate = .1 item = 89.95 discount = item * discount_rate print("The discount on this item is $", discount)) Output: The discount on this item is $ 8.995000000000001
my_name = "Donny", names = ["Lizzy", "Mike", "Joel", "Anne"]
Given the following code, what is the value of my_name and what does the list consist of after the second statement is executed? names = ["Lizzy", "Mike", "Joel", "Anne", "Donny"] my_name = name.pop()
ages = [22, 35, 24, 4, 17, 28]
Given the following code, what would the list consist of after the second statement? ages = [22, 35, 24, 17, 28] ages.insert(3, 4)
None: Index error
Given the following list, what is the value of ages[5]? ages = [22, 35, 24, 17, 28]
a pass statement
If you want to code an if clause, but you don't want to perform any action, you can code
before the loop is executed
In a while loop, the Boolean expression is tested
the coding of control structures
Pseudocode can be used to plan
all of the above
Python comments
all of the above
Python is considered a good first language to learn because:
Indentation
Python relies on correct __________ to determine the meaning of a statement.
systems
The __________ software for a computer provides the software that's needed for running applications.
higher precedence than the or operator, but lower precedence than the not operator
The and operator has
main memory
The data in __________ is lost when an application ends.
disk storage
The data in __________ is persistent so it is not lost when an application ends.
a shebang line
The following is an example of __________. #!/usr/bin/env python 3
source code
The following is an example of __________. print("Hello out there!") # get input name = input("Who are you?") print("Goodbye, " , name)
debugging
The goal of __________ is to find all the errors in a program.
testing
The goal of __________ is to find all the errors in a program.
...
The stack is available when an exception occurs. It displays a list of
lower() method to convert all characters in each string to lowercase.
To compare two strings with mixed uppercase and lowercase letters, a programmer can first use the
a while statement
Which of the following begins by testing a condition defined by a Boolean expression and then executes a block of statements if the condition is true?
flag = True
Which of the following creates a Boolean variable?
Float
Which of the following data types would you use to store the number 25.62?
pRate
Which of the following doesn't follow the best naming practices for variables?
If the condition in the if clause is true, the statements in that clause are executed.
Which of the following is true for an if statement that has both elif and else clauses?
the Python virtual machine
Which of the following translates bytecode into instructions for the computer?
firstName
Which of the following variable names uses camel case?
my_number = float(input("Enter a number:"))
Which of the following will get a floating-point number from the user?
syntax errors
Which type of errors must be fixed before the program can be compiled?
Boolean
Which type of expression has a value of either true or false?
What will be the result of the following code if the user enters 81 at the prompt? score_curve = 7 score = input("Enter your score on the exam: ") score_curve += score print(score_curve)
error: you cannot use the += operator to add a string variable to an int value error: