python gmetrix practice

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/76

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:20 AM on 5/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

77 Terms

1
New cards

Which of the following keywords is able to turn a False into a True and is also known as a 'logical inverter'

not

2
New cards

Which of the following modes of file writing would be most appropriate for a program designed to update the contents of a .txt file and to overwrite the entire file if the file contains any data.

w

3
New cards

Suggest why a program may be broken down into individual functions

Reuseability. Encourages code reuse by moving common operations to a separate function.

Debugability. It's easier to debug simple functions than complex ones

.Maintainability. Smaller, simpler functions are easier to maintain.

4
New cards

____ is a programming paradigm that provides a means of structuring programs so that properties and behaviors are bundled into individual objects.

Object-oriented programming

5
New cards

Which of the following modes is most suitable for writing a binary file in Python?

wb

6
New cards

A programmer tries to run the following code. What error is likely to be raised in this instance?

#Example:

print('Hello world')s

syntax error

7
New cards

What is the value of the variable 'a' after it passes through the loops?

a = 0

for i in range(2):

for j in range(3):

a += i + j

9

8
New cards

Which line of code inserted in the program will add a random item from the list each time the loop runs?

import random

option_list = ['candy', 'souvenir', 'gift card', 'stickers', 'book', 'poster']

prize_list = []

for counter in range(3):

# Line of code goes here

prize_list.append(rand_item)

rand_item = random.choice(option_list)

9
New cards

What is the value of the variable 'c' in the following code snippet?

a = 2

b = 1

c = a << b

4

10
New cards

Which of the following best describes the randint function of the random module. Consider the example code below to see the code in context.

x = random.randint(2,5)

producing a random integer between 2-5 (inclusive of 2 and 5)

11
New cards

A data structure that can't be changed after its creation is known as _____?

immutable

12
New cards

Which of the following shows the correct way to initialize a single dimension array?

arr = ['Kan', 'Ryne', 'Em']

arr = []

13
New cards

What is the value returned from this code?

print(type(True))

14
New cards

What is the value of the variable 'c' in the following code snippet?

a = 7

b = 8

c = a ^ b

15

15
New cards

Which of the following modes of file reading would be most appropriate for a program designed to update the contents of a .txt file without making any new deletion to the file.

a

16
New cards

Which methods would be used to generate random numbers in Python?

random.random()

random.randint()

random.uniform()

17
New cards

andom.random()random.randint()random.uniform()

TypeError

18
New cards

What is the type of the variable c in the code snippet?

a = int(3)

b = int('car')

c = a + b

This will raise an error.

19
New cards

What is the value returned from this code?

print(type(4))

20
New cards

Which of the following best describes the randint function of the random module. Consider the example code below to see the code in context.

x = random.randint(1,5)

producing a random integer between 1-5 (inclusive of 1 and 5)

21
New cards

Which of the following best describes 'sklearn'? 'sklearn' (scikit-learn) provides Machine Learning operations and it contains simple and efficient tools for predictive data analysis

a package

22
New cards

A programmer tries to run the following code. What error is likely to be raised in this instance?

#Example:

print(int('cat'))

ValueError

23
New cards

A programmer has created a string with a single speech mark on one side and double speech mark on the other. What error is likely to be raised in this instance?

#Example:

var1 = 'Hello"

syntaxerror

24
New cards

What is the output of the following code?

x = 10

y = 10

z = 0

z = x + y

print(z)

20

25
New cards

An operation that modifies a variable without making a copy is known as ....

in-place operation

26
New cards

Which statement would assign the input.txt file to the handler fin?

fin = open("input.txt", "r")

27
New cards

What is the output from the following print statement?

print(('Trolls :{0} Knights :{1} and {other}').format(45, 55, other='Princesses'))

Trolls :45 Knights :55 and Princesses

28
New cards

A programmer accidentally attempts convert the type of an object and receives the next error: 'int() cannot convert 'dog' into an integer'. What error was likely raised in this instance?

ValueError

29
New cards

What would be the lowest value printed by this code?

for i in range(12):

print(i)

0

30
New cards

What is the result of the following if statement?

def func(j):

if j > 10 and j < 20:

return True

else:

return False

when j is 15 the result is True

when j is 20 the result is False

31
New cards

What is the output of the following code?

x = 10

a = 0

print(x > a)

true

32
New cards

Which of the following casts could result in a run time error?

int("j")

33
New cards

Using the Math module to perform a calculation, what should be output of "math.sqrt(25)"?

5.0

34
New cards

What is the output of the following code?

x, y = 10, 20

min = x if x < y else y

print(min)

10

35
New cards

Match the print statement to it's output?

trolls and knights

knights and trolls

Trolls and "Knights"

Trolls and Knights

36
New cards

What is the output of the following code snippet?

careful = 1

second_chance = True

if careful:

print('I got a second chance at this!')

elif second_chance:

print('I am not being careful...')

else:

print('I am being careful!')

'I got a second chance at this!'

37
New cards

Which of the following lines represents a valid comment?

# print('Content')

38
New cards

Which collection structure allows items that are ordered and changeable and contain duplicate values?

List

39
New cards

Which of the following code snippets would be the correct way to import everything from a module

import randint as ra # Option 1

from random import * # Option 2

as ra import randint # Option 3

from random as ra import randint # Option 4

option 2

40
New cards

What is the value of j after the following calculation?

j = 5 ** 2

25

41
New cards

Which of the following methods allows single items from a list to be deleted and to be returned as individual elements? Use the example below for context.

list_one = [1, 2, 3]

list_one.method()

list_one = [1, 2]

pop()

42
New cards

Consider a program which manages its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer. Which of the following words is suitable for describing the previous program.

Multithreading

43
New cards

What would be the output for the following code?

arr = ['Mug', 'Plate', 'Bowl', 'Saucer', 'Glass']

print(arr[2])

Bowl

44
New cards

Will this program cause an error? If not, what will the value be of you_can_pass?

# possessions

staf = True

christal_ball = True

shield = True

sword = False

you_can_pass = staf and christal_ball or sword and shield

True

45
New cards

Which of the following statements are true?

Python code is structured and indented blocks must be used

46
New cards

What is the value returned from this code?

print(type('?'))

47
New cards

What are Runtime Errors in Python?

Errors that show up when the script is attempting to perform operations on data of the wrong type

Errors that occur because of misspelled or incorrectly capitalized variable and function names

48
New cards

Which of the following keywords is able to turn a True into a False, and is also known as a 'logical inverter'

not

49
New cards

A data structure where the type or the class is less important than the methods it defines is known as what?

duck type

50
New cards

What would be the output of the round() function when this code is evaluated?

x = 1

if(x == 1):

print(round(4.9))

else:

print(round(6.9))

5

51
New cards

What is the output of the following code snippet?

careful = 0

second_chance = True

if careful:

print('I got a second chance at this!')

elif second_chance:

print('I am not being careful...')

else:

print('I am being careful!')

'I am not being careful...'

52
New cards

Which statement would read the entire file contents?

fin.read()

53
New cards

What would be the highest value printed by this code?

for i in range(12):

print(i)

11

54
New cards

Assume you have written your Python code in a separate file named 'myfunctions.py'. Which of the following statements shows the correct syntax for adding it to your new Python script so the code can be used?

import myfunctions

55
New cards

Which of the following best describes 're'? 're' (regular expression) provides regular expression matching operations similar to those found in Perl.

module

56
New cards

How many except statements can a try-except block have?

at least one

57
New cards

Please select the correct answer regarding the following code

v = 'Kim'

x = '{}'.format('Kim')

print(v is x)

Output will be True

Both variables contain string objects

58
New cards

Which collection structure stores items in key value pairs?

dictionary

59
New cards

What is the output of the following code?

x = 5

y = 2

y-=1

print(x, y)

5,1

60
New cards

Which list function returns the number of items contained in the list?

len(listname)

61
New cards

Which collection structure allows items that are ordered, changeable, and does not allow duplicate values?

dictionary

62
New cards

What is the value of the variable 'c' in the following code snippet?

a = 3

b = 5

c = a > b

false

63
New cards

What is the value of the variable 'c' in the following code snippet?

a = 2

b = 1

c = a << b

4

64
New cards

What will happen when the user enters 12?

month_list = ['January', 'February', 'March', 'April', 'May',

'June', 'July', 'August', 'September',

'October', 'November', 'December']

month_number = int(input('Enter the number of your favorite month:')) print('Your favorite month is ' + month_list[month_number] + '!')

There will be an error caused by trying to access index 12

65
New cards

Order these lines of code so that the program checks each item in the list and adds them to the short_pets list if the length of their name is less than 5. Then output the short_pets list.

pet_list = ['cat', 'dog', 'lizard', 'parrot', 'fish', 'turtle'] short_pets = []

for pet in pet_list:

if len(pet) < 5:

short_pets.append(pet)

print(short_pets)

66
New cards

What would be the output for the following code?

arr = ['Mug', 'Plate', 'Bowl', 'Saucer', 'Glass']

arr2 = arr[1:4] print(arr2)

Plate', 'Bowl', 'Saucer'

67
New cards

Whats is the proper shebang to indicate the script is using Python version 3?

#!/usr/bin/env python3

68
New cards

What is the value of the variable 'c' in the following code snippet?

-4

69
New cards

Which code would allocate and initialize a list of 10 integers?

nlist = [0] * 10

70
New cards

Which of the following is used to define a block of code in Python?

indentation

71
New cards

Identify the Python comment.

Comment 3

72
New cards

Which of the following shows the correct way to initialize a multidimensional array?

arr = []

arr = [[]]

73
New cards

Consider the following piece of code. Which of the following is true?

from sklearn.linear_model import LinearRegression

linear_model is a module of sklearn package

74
New cards

Which of the following characters is used for single-line comments in Python?

#

75
New cards

Which of the following methods allows multiple items from a string to be added as individual elements to an existing list? Use the example below for context

list_one = [1,2,3]

string_one = 'abc' list_one.method(string_one)

list_one = [1, 2, 3, 'a', 'b', 'c']

extend()

76
New cards

What is the purpose of the following code?

try: a = int(b) except: print('Error')

Trap an invalid integer value

77
New cards