Python I Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the output? subjects = ["Math", "Science", "Python", "English", "PE"] print(subjects[2])

Python

What is the output of the following code? scores = [20, 30, 15, 10] scores.append(45) scores.insert(1, 25) print(scores)

[20, 25, 30, 15, 10, 45]

What is the output of the following code if 5 is entered for newNum? numbers = [6, 7, 8, 3] newNum = input("Enter a number: ") numbers.append(newNum) print(numbers)

[6, 7, 8, 3, '5']

What is the output of the following Python code? print("\\/\\/elcome\thome!"

\/\/elcome (4 spaces) home!

What does the input() function return?

a string value

The variable in a loop that will allow the programmer to keep a running total and is usually incremented or decremented by a varying amount is called a(n) _______

accumulator

What is the output of the below program def cube(x): return x * x * x x = cube(3) print(x)

27

To take the items in a list and connect them together as one string you can use the ____ function.

join

Which of the following is a valid Python comment structure.

# this is a comment

The index number of the last character for a string in Python is ______.

-1

Which code formats the string "Yellow" to "YELLOW"?

.upper()

While loops can execute this possible number of times.

0, finite, or infinite

What is the best estimate for the output of the code below? calculation = 5 + 15 +/ 5 + 3 * 2 - 1

13.0

What output? numbers = [] for num in range(5): numbers.append(num*2) print(numbers[3])

6

Which operator can be used to compare two values.

==

In Python string comparisons, lower case "a" is less than upper case "A"

False

What is the output of the following code? cars = ["Ford", "Chevy", "Honda", "Jeep"] for car in cars: print(car, end=".")

Ford- Chevy- Honda- Jeep- (A)

assignment = 25 if assignment = 25: print("use "=" to assign values" else: pass

SyntaxError

What is "print" used for?

To display output

What is the output of the following code? myWord = "LEGOS" print(myWord(4))

TypeError

What is the output of the following code? myWord = "PUZZLE" print(myWord[2 : 5])

ZZL

A function in Python can have _____ parameter(s).

as many as needed

Choose the item that best completes the following sentence: "A Python list..."

can contain both strings and numbers together as list items

____ is the Python keyword used in EVERY function that the programmer creates

def

Which of the following is the correct way to create an empty list in python?

empList = []

Which parameter would you change in a Python print function to keep the item printed on the same line?

end

What structure will allow the programmer to iterate through a string easily 1 character at a time.

for - in loop

What does type(-38) return?

int

What is the general syntax for a function to delete a specific object (value) from a list in Python?

listName.remove(value)

Which of the following is a correct way to add each individual element from one list to another list in Python?

listOne.append(listTwo)

Which snippet of code below will display the 3rd character in the variable myWord if myWord = "VANILLA"

myWord[2]

What is the correct general syntax for the range function in Python?

range(start, stop, step)

Choose the correct output of calling the function below with the call statement below: def lowCase(words): return words.lower() myPhrase = lowCase ("Return THIS lower") print(myPhrase)

return this lower

By default, the split function in Python will split a string at each ____ and make a list with each word as an item in the list.

space

The index number for the first character for all strings in Python is _____.

0

What will be displayed by the following code? count = 5 while True: print("Hello") count += 1 if count >= 8: break

A "Hello Hello Hello"

The programmer wants to stop the loop when the user types the letter 'Q' in regardless of how they type it. What kind of error occurs in this code and how can it be fixed? while letter != 'Q' letter = input("Enter a letter (Q to stop): ") print("You entered" + word)

A logic error that can be fixed by converting the input to upper case.

What is the output of the following code if the grade variable has a value of 92? if grad >= 60: print("Passing grade of: ") if grade >= 60: print("D") elif grade >= 70: print("C") elif grade >= 80: print("B") elif grade >= 90: print("A") else: print("Failing grade")

Passing grade of: D

What is the output of the following code? bands = ["Eagles", "ACDC", "Queen", "Air Supply"] bands.append(bands[0]) print(bands)

["Eagles", "ACDC", "Queen", "Air Supply", "Eagles"]

Like else, the elif can execute only when the previous if conditional evaluates False.

True

Using comma separation, we can combine strings and numbers (int & float) in a single Python print() function without a TypeError.

True

score = 3 + "45 result in?

TypeError

Which general Python command below will overwrite (change) an existing value in a list?

listName[index] = newValue

What is the correct order of the values A, B, C when slicing a string in Python? myString[A : B : C]

start index, stop index, step interval

Which of the following is a Python function?

print( )

What is the output from running the code below? sizeNum = "8 9 10" size = "8" # user input if size.isdigit() == False: print("Invalid: size should only use digits") elif int(size) < 8: print("size is too low" elif size in sizeNum: print("size is recorded") else: print("size is too high"

size is recorded

Which are the advantages of using functions in Python?

Improving clarity, reducing code duplication, and decomposing complex problems

def subtotal(orderAmt, salesTax): if orderAmt > 0: subtotal - int(orderAmt) * (1 + float(salesTax) return subtotal else: return "Invalid order amount."

OrderTotal = subtotal(500, 0.07)

Which loop header below will allow the program to iterate through the string myWord starting at the first letter and advancing every 3rd letter?

for ltr in myWord[ : : 3]

A while True loop is sometimes referred to as a ____ loop.

forever (infinite) loop


Set pelajaran terkait

CJL4410 - Criminal Procedure, UF CJL4410 Exam 1

View Set

Anatomy & Physiology II: The Male Reproductive System

View Set

_5_ PAP Medical Payments Coverage

View Set

AP Computer Science A Unit 7 Progress Check: MCQ

View Set

global medieval europe, crusades, plague, renaissance

View Set