Computer Programming Gaddis Python Chapter 2 Notes

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/71

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.

72 Terms

1
New cards

What is the first step in the program development cycle?

Design the program.

2
New cards

What is pseudocode?

An informal language used to create a model program without syntax rules.

3
New cards

What is a flowchart?

A diagram that graphically depicts the steps in a program.

4
New cards

What are the three main steps in the input, processing, and output model?

Receive input, perform a process on the input, and produce output.

5
New cards

What does the print function do in Python?

Displays output on the screen.

6
New cards

What is a string in programming?

A sequence of characters used as data.

7
New cards

What is the purpose of comments in a Python program?

To provide notes of explanation that are ignored by the interpreter.

8
New cards

What is a variable in Python?

A name that represents a value stored in the computer's memory.

9
New cards

What is the general format for an assignment statement in Python?

variable = expression.

10
New cards

What are the rules for naming variables in Python?

Cannot be a keyword, cannot contain spaces, must start with a letter or underscore, and are case sensitive.

11
New cards

What is multiple assignment in Python?

Assigning values to multiple variables in a single statement, e.g., x, y, z = 0, 1, 2.

12
New cards

What is garbage collection in Python?

The removal of values that are no longer referenced by variables.

13
New cards

What does the input function do in Python?

Displays a prompt and reads input from the keyboard, returning it as a string.

14
New cards

How do you display multiple items with the print function?

Separate items with commas when passing them as arguments.

15
New cards

What is a numeric literal?

A number written in a program, where no decimal point is considered an int and otherwise a float.

16
New cards

What is string concatenation?

The process of joining two or more strings together.

17
New cards

What is the significance of the assignment operator in Python?

It is used to create a variable and make it reference data.

18
New cards

What is the difference between a string literal and a string?

A string literal is the actual text in the code, while a string is the data type that represents a sequence of characters.

19
New cards

What is the output of the following code? print('Hello world')

'Hello world'

20
New cards

What does it mean for a variable to be case sensitive?

Variable names that differ only in case are considered different variables.

21
New cards

What is the purpose of the prompt in the input function?

To instruct the user to enter a value.

22
New cards

What is the role of the print function's arguments?

They are the data that will be displayed on the screen.

23
New cards

What happens if you try to use a variable without assigning a value to it?

You will encounter an error.

24
New cards

What is the significance of using triple quotes for strings?

They allow for multi-line strings and can contain both single and double quotes.

25
New cards

What is an assignment statement example in Python?

age = 29.

26
New cards

What does it mean for a variable to reference a value?

It means the variable is linked to that value stored in memory.

27
New cards

What does the input function always return?

A string

28
New cards

How do you convert a string input to an integer in Python?

Use int(item) function

29
New cards

What function converts a string input to a float?

Use float(item) function

30
New cards

What is a nested function call?

A function that calls another function as an argument

31
New cards

What happens if type conversion is attempted on an invalid numeric value?

It causes an error

32
New cards

What does the statement 'number = int(input('Enter a number: '))' do?

Displays a prompt, reads input as a string, converts it to an int, and assigns it to the variable 'number'

33
New cards

What is the purpose of the / operator in Python?

Performs floating point division

34
New cards

What does the // operator do?

Performs integer division, truncating positive results and rounding negative results away from zero

35
New cards

What is operator precedence in Python?

The order in which operations are performed, with parentheses having the highest precedence

36
New cards

What does the exponent operator (**) do?

Raises a number to a power

37
New cards

What is the remainder operator (%) used for?

Performs division and returns the remainder

38
New cards

How does type conversion work in mixed-type expressions?

The int is temporarily converted to float for operations involving both types

39
New cards

What character allows breaking long statements into multiple lines?

The backslash character

40
New cards

What is implicit string literal concatenation?

Adjacent string literals are automatically combined into a single string

41
New cards

How can you change the default item separator in the print function?

Use the special argument sep='delimiter'

42
New cards

What is an f-string in Python?

A special type of string literal prefixed with 'f' that supports variable placeholders

43
New cards

How can you format a floating-point number to two decimal places using an f-string?

Use the format specifier .2f

44
New cards

What is a magic number in programming?

An unexplained numeric value that appears in code, making its purpose unclear

45
New cards

Why are magic numbers problematic?

They can make it difficult to determine the purpose of the number in the code

46
New cards

What does the statement 'print(f'{num:,.2f}')' do?

Formats the number with commas and two decimal places

47
New cards

How do you align values within a field in an f-string?

Use < for left alignment, > for right alignment, and ^ for center alignment

48
New cards

What is the order of designators in a format specifier for f-strings?

[alignment][width][,][.precision][type]

49
New cards

What are named constants?

Named constants are identifiers that represent fixed values that do not change during program execution, improving code readability and maintainability.

50
New cards

Give an example of a named constant.

INTEREST_RATE = 0.069

51
New cards

What is the advantage of using named constants over magic numbers?

They make code self-explanatory, easier to maintain, and help prevent typographical errors.

52
New cards

How do you import the turtle graphics module in Python?

Use the statement: import turtle

53
New cards

What command moves the turtle forward by a specified number of pixels?

turtle.forward(n)

54
New cards

What is the initial heading of the turtle in degrees?

0 degrees (east)

55
New cards

How do you turn the turtle right by a specific angle?

Use the command: turtle.right(angle)

56
New cards

What command sets the turtle's heading to a specific angle?

turtle.setheading(angle)

57
New cards

What does the turtle.penup() command do?

It raises the turtle's pen so that it does not draw while moving.

58
New cards

What command is used to draw a circle with a specified radius?

turtle.circle(radius)

59
New cards

How do you change the width of the turtle's pen?

Use the command: turtle.pensize(width)

60
New cards

What command sets the background color of the turtle's window?

turtle.bgcolor(color)

61
New cards

What does the turtle.reset() command do?

It erases all drawings, resets the turtle's position and color, but does not change the background color.

62
New cards

How do you move the turtle to a specific coordinate?

Use the command: turtle.goto(x, y)

63
New cards

What command changes the speed of the turtle's movement?

turtle.speed(speed)

64
New cards

What does the turtle.hideturtle() command do?

It hides the turtle icon without affecting the drawing.

65
New cards

How do you display text in the turtle graphics window?

Use the command: turtle.write(text)

66
New cards

What is the purpose of the turtle.begin_fill() command?

It starts the process of filling a shape with color.

67
New cards

How do you get numeric input from a dialog box in turtle?

Use the command: turtle.numinput('Input', 'Enter your age')

68
New cards

What command keeps the turtle graphics window open after the program finishes?

turtle.done()

69
New cards

What is the purpose of the turtle.clear() command?

It erases all drawings without changing the turtle's position or color.

70
New cards

How can you specify a default value in turtle.numinput?

By using the syntax: turtle.numinput('Input', 'Enter a number', default=10)

71
New cards

What command is used to fill a shape with a color after drawing it?

turtle.end_fill()

72
New cards

What does the turtle.dot() command do?

It draws a simple dot at the turtle's current location.

Explore top flashcards

World Lit Midterm
Updated 1046d ago
flashcards Flashcards (25)
Vývinovka
Updated 506d ago
flashcards Flashcards (66)
Units 1-12 of Vocab
Updated 1052d ago
flashcards Flashcards (240)
BIO Final 2023
Updated 692d ago
flashcards Flashcards (159)
Chapter 2
Updated 777d ago
flashcards Flashcards (30)
World Lit Midterm
Updated 1046d ago
flashcards Flashcards (25)
Vývinovka
Updated 506d ago
flashcards Flashcards (66)
Units 1-12 of Vocab
Updated 1052d ago
flashcards Flashcards (240)
BIO Final 2023
Updated 692d ago
flashcards Flashcards (159)
Chapter 2
Updated 777d ago
flashcards Flashcards (30)