Computer Science I Final

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/50

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

51 Terms

1
New cards

What are the five major components of a computer system?

CPU, main memory, secondary storage, input devices, and output devices

2
New cards

What is the purpose of ASCII?

ASCII (American Standard Code for Information Interchange) is used to represent characters such as english letters as numeric codes, facilitating text storage and communication between computers.

3
New cards

What is a "magic number" in programming?

A magic number is an unexplained value that appears directly in a program's code, often representing some important quantity but lacking context or documentation.

4
New cards

What is a sentinel value, and how is it used?

A sentinel value is a special value used to mark the end of a sequence of data. It is distinct from the actual data values. Sentinels are used to control loops that process input.

5
New cards

What are list comprehensions?

List comprehensions provide a concise way to create new lists based on existing lists or other iterables.

6
New cards

What are the advantages and disadvantages of high-level programming languages compared to low-level languages like assembly?

High-level languages are easier to read and write but slower to execute than low-level languages.

7
New cards

What is the primary difference between a compiler and an interpreter?

A compiler translates the entire program into machine code before execution, while an interpreter translates the program line by line.

8
New cards

How do you format numeric output in Python?

Use f-strings or format() to control the number of decimals, padding, etc.

9
New cards

What are named constants, and why are they useful?

Variables with fixed values that are defined and cannot be changed during execution.

10
New cards

What are relational operators, and how are they used in decision-making?

Relational operators compare values to determine true or false (e.g., ==, >, <)

11
New cards

How do logical operators (and, or, not) create compound Boolean expressions?

and and or combine multiple conditions, while not inverts a condition.

12
New cards

What is a Boolean variable, and how is it used as a flag in programs?

A Boolean variable can store True or False values and is used to control program flow or indicate state.

13
New cards

Explain the difference between condition-controlled loops (while) and count-controlled loops (for). Provide examples of when each type is appropriate.

  • while loop: Repeats as long as a condition is true. Appropriate when the number of iterations is unknown or based on dynamic conditions.

  • for loop: Repeats a set number of times, often iterating over a sequence like a list or range. Appropriate when the number of iterations is known in advance.

14
New cards

Explain the importance of input validation and how to implement it using loops.

Input validation ensures that the data entered by the user is of the correct type and meets specified criteria. It can be implemented using loops to repeatedly ask the user for input until valid data is provided.

15
New cards

What are functions, and why are they important in programming?

Functions are blocks of code that perform a specific task and can be reused. They help make code more modular, organized, and easier to maintain.

16
New cards

When using the // operator to perform division, what happens if the result is a negative number?

The result is rounded away from zero to the nearest integer.

17
New cards

When using the // operator to perform division, what happens if the result is a positive number?

The result is truncated (meaning, the fractional part is thrown away).

18
New cards

What will be displayed after the following code is executed?

 

def pass_it(x, y):

    z = x*y

    result = get_result(z)

    return(result)

 

def get_result(number):

    z = number + 2

    return(z)

 

num1 = 3

num2 = 4

answer = pass_it(num1, num2)

print(answer)

14

19
New cards

Which of the following will display 20%?

print(f'{0.2:.0%}')

20
New cards

What is the output of the following code?

 

val = 123.456789

print(f'{val:.3f}')

123.457

21
New cards

The encoding technique used to store negative numbers in the computer's memory is called

two’s complement

22
New cards

What is the output of the following statement?

print('One'

      'Two'

      'Three')

OneTwoThree

23
New cards

What is the decimal value of the following binary number?

10011101

157

24
New cards

The decision structure that has two possible paths of execution is known as

Dual alternative

25
New cards

What will be displayed after the following code is executed?

 

total = 0

for count in range(1,4):

    total += count

print(total)

6

26
New cards

Which of the following is not a major component of a typical computer system?

CPU

Operating system

Main memory

Secondary storage devices

Operating System

27
New cards

What does the following statement mean?

num1, num2 = get_num()

The function get_num() is expected to return a value for num1 and for num2.

28
New cards

What will be the output after the following code is executed?

 

def pass_it(x, y):

    z = x , ", " , y

 

num1 = 4

num2 = 8

answer = pass_it(num1, num2)

print(answer)

None

29
New cards

What is the difference between the remove method in a list and using the del statement?

The remove method searches for and removes an element containing a specific value. The del statement removes an element at a specific index.

30
New cards

Assume the following statement appears in a program.

names = []

Why is the append function used instead of names[0] to add to the list at index 0?

This is because the index 0 does not exist. If you tried names[0], an error would occur.

31
New cards

What does the index function in lists do?

It searches for an item in the list and returns the index of the first element containing that item.

32
New cards

What does the reverse function in lists do?

It reverses the order of items in the list.

33
New cards

Write a set of nested loops that display the contents of the numbers list.

numbers = [[1,2], [10,20], [100,200], [1000,2000]]

for r in range(4):

for c in range(2):

print(numbers[r][c])

34
New cards

Why do tuples exist?

Processing a tuple is faster than processing a list so it’s more helpful when processing large amounts of data.

Tuples are safe because the contents cannot be modified after being created.

35
New cards

What is a program?

A program is a set of instructions that a computer follows to perform a task

36
New cards

What are the five major components of a computer system?

CPU, main memory, secondary storage devices, input devices, output devices

37
New cards

What does an assembler do?

It translates assembly language to machine language.

38
New cards

What part of the computer serves as a work area to store a program and its data while the program is running?

Main memory

39
New cards

What part of the computer stores data for a long period of time, even when there is no power to the computer?

Secondary storage

40
New cards

What fundamental set of programs control the internal operations of the computer’s hardware?

Operating System

41
New cards

What is a program that performs a specialized task such as a virus scanner?

Utility Program

42
New cards

In what numbering system are all numeric values written as sequences of 0s and 1s?

Binary numbering system

43
New cards

What does digital data mean?

Data that is stored in binary format

44
New cards

What is a digital device?

Any device that works with binary data

45
New cards

When a CPU executes the instructions in a program, it is engaged in what process?

Fetch-decode-execute cycle

46
New cards

What is assembly language?

It is a language that uses short words known as mnemonics for instructions.

47
New cards

What are the steps in the program development cycle?

Design the program

Write the code

Correct syntax errors

Test the program

Correct logic errors

48
New cards

The % symbol is the remainder operator, also known as _______ operator.

modulus, mod

49
New cards

A(n) _________ character is a special character that is preceded by a backslash (\), appearing inside a string literal.

escape

50
New cards

The __________ specifier is a special set of characters that specify how a value should be formatted.

formatting

51
New cards

In the expression 12.45 + 3.6, the values to the right and left of the + symbol are the

operands