1/71
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the first step in the program development cycle?
Design the program.
What is pseudocode?
An informal language used to create a model program without syntax rules.
What is a flowchart?
A diagram that graphically depicts the steps in a program.
What are the three main steps in the input, processing, and output model?
Receive input, perform a process on the input, and produce output.
What does the print function do in Python?
Displays output on the screen.
What is a string in programming?
A sequence of characters used as data.
What is the purpose of comments in a Python program?
To provide notes of explanation that are ignored by the interpreter.
What is a variable in Python?
A name that represents a value stored in the computer's memory.
What is the general format for an assignment statement in Python?
variable = expression.
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.
What is multiple assignment in Python?
Assigning values to multiple variables in a single statement, e.g., x, y, z = 0, 1, 2.
What is garbage collection in Python?
The removal of values that are no longer referenced by variables.
What does the input function do in Python?
Displays a prompt and reads input from the keyboard, returning it as a string.
How do you display multiple items with the print function?
Separate items with commas when passing them as arguments.
What is a numeric literal?
A number written in a program, where no decimal point is considered an int and otherwise a float.
What is string concatenation?
The process of joining two or more strings together.
What is the significance of the assignment operator in Python?
It is used to create a variable and make it reference data.
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.
What is the output of the following code? print('Hello world')
'Hello world'
What does it mean for a variable to be case sensitive?
Variable names that differ only in case are considered different variables.
What is the purpose of the prompt in the input function?
To instruct the user to enter a value.
What is the role of the print function's arguments?
They are the data that will be displayed on the screen.
What happens if you try to use a variable without assigning a value to it?
You will encounter an error.
What is the significance of using triple quotes for strings?
They allow for multi-line strings and can contain both single and double quotes.
What is an assignment statement example in Python?
age = 29.
What does it mean for a variable to reference a value?
It means the variable is linked to that value stored in memory.
What does the input function always return?
A string
How do you convert a string input to an integer in Python?
Use int(item) function
What function converts a string input to a float?
Use float(item) function
What is a nested function call?
A function that calls another function as an argument
What happens if type conversion is attempted on an invalid numeric value?
It causes an error
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'
What is the purpose of the / operator in Python?
Performs floating point division
What does the // operator do?
Performs integer division, truncating positive results and rounding negative results away from zero
What is operator precedence in Python?
The order in which operations are performed, with parentheses having the highest precedence
What does the exponent operator (**) do?
Raises a number to a power
What is the remainder operator (%) used for?
Performs division and returns the remainder
How does type conversion work in mixed-type expressions?
The int is temporarily converted to float for operations involving both types
What character allows breaking long statements into multiple lines?
The backslash character
What is implicit string literal concatenation?
Adjacent string literals are automatically combined into a single string
How can you change the default item separator in the print function?
Use the special argument sep='delimiter'
What is an f-string in Python?
A special type of string literal prefixed with 'f' that supports variable placeholders
How can you format a floating-point number to two decimal places using an f-string?
Use the format specifier .2f
What is a magic number in programming?
An unexplained numeric value that appears in code, making its purpose unclear
Why are magic numbers problematic?
They can make it difficult to determine the purpose of the number in the code
What does the statement 'print(f'{num:,.2f}')' do?
Formats the number with commas and two decimal places
How do you align values within a field in an f-string?
Use < for left alignment, > for right alignment, and ^ for center alignment
What is the order of designators in a format specifier for f-strings?
[alignment][width][,][.precision][type]
What are named constants?
Named constants are identifiers that represent fixed values that do not change during program execution, improving code readability and maintainability.
Give an example of a named constant.
INTEREST_RATE = 0.069
What is the advantage of using named constants over magic numbers?
They make code self-explanatory, easier to maintain, and help prevent typographical errors.
How do you import the turtle graphics module in Python?
Use the statement: import turtle
What command moves the turtle forward by a specified number of pixels?
turtle.forward(n)
What is the initial heading of the turtle in degrees?
0 degrees (east)
How do you turn the turtle right by a specific angle?
Use the command: turtle.right(angle)
What command sets the turtle's heading to a specific angle?
turtle.setheading(angle)
What does the turtle.penup() command do?
It raises the turtle's pen so that it does not draw while moving.
What command is used to draw a circle with a specified radius?
turtle.circle(radius)
How do you change the width of the turtle's pen?
Use the command: turtle.pensize(width)
What command sets the background color of the turtle's window?
turtle.bgcolor(color)
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.
How do you move the turtle to a specific coordinate?
Use the command: turtle.goto(x, y)
What command changes the speed of the turtle's movement?
turtle.speed(speed)
What does the turtle.hideturtle() command do?
It hides the turtle icon without affecting the drawing.
How do you display text in the turtle graphics window?
Use the command: turtle.write(text)
What is the purpose of the turtle.begin_fill() command?
It starts the process of filling a shape with color.
How do you get numeric input from a dialog box in turtle?
Use the command: turtle.numinput('Input', 'Enter your age')
What command keeps the turtle graphics window open after the program finishes?
turtle.done()
What is the purpose of the turtle.clear() command?
It erases all drawings without changing the turtle's position or color.
How can you specify a default value in turtle.numinput?
By using the syntax: turtle.numinput('Input', 'Enter a number', default=10)
What command is used to fill a shape with a color after drawing it?
turtle.end_fill()
What does the turtle.dot() command do?
It draws a simple dot at the turtle's current location.