Docsity

Python Programming Exam Review, Exams of Advanced Education

Toggle sidebar
bg1
Python Programming Exam Review With
100% Correct And Verified Answers
forward(distance) - Correct Answer-moves turtle forward distance in current direction
backward(distance) - Correct Answer-moves turtle backward in current direction
circle(radius) - Correct Answer-moves the turtle in a circle. Within the parentheses, you
write the radius of the circle.
penUp, penDown - Correct Answer-controls whether or not Tracy is leaving a trail.
What are the dimensions of Tracy's world? - Correct Answer-400 pixel tall x 400 pixels
wide
left(angle), right(angle) - Correct Answer-turns Tracy either left or right the inputted
degrees
For loops - Correct Answer-used to repeat commands a certain number of times.
What is the code for a for loop? - Correct Answer-for i in range(times to repeat):
Indented commands here
setposition(x,y) - Correct Answer-moves Tracy to the designated coordinate.
speed(number 0-10) - Correct Answer-Sets how quickly Tracy will move through the
code.
speed(1)=Slowest
speed(5)=Medium
speed(10)=Fastest
speed(0)=Immediate
# comment here
"""
comment here
'''' - Correct Answer-In-line comment
Multi-line comment
What is the code for defining?
How do you call it? - Correct Answer-def function_name_here():
pf3
pf4
pf5

Partial preview of the text

Download Python Programming Exam Review and more Exams Advanced Education in PDF only on Docsity!

Python Programming Exam Review With

100% Correct And Verified Answers

forward(distance) - Correct Answer-moves turtle forward distance in current direction backward(distance) - Correct Answer-moves turtle backward in current direction circle(radius) - Correct Answer-moves the turtle in a circle. Within the parentheses, you write the radius of the circle. penUp, penDown - Correct Answer-controls whether or not Tracy is leaving a trail. What are the dimensions of Tracy's world? - Correct Answer-400 pixel tall x 400 pixels wide left(angle), right(angle) - Correct Answer-turns Tracy either left or right the inputted degrees For loops - Correct Answer-used to repeat commands a certain number of times. What is the code for a for loop? - Correct Answer-for i in range(times to repeat): Indented commands here setposition(x,y) - Correct Answer-moves Tracy to the designated coordinate. speed(number 0-10) - Correct Answer-Sets how quickly Tracy will move through the code. speed(1)=Slowest speed(5)=Medium speed(10)=Fastest speed(0)=Immediate

comment here

""" comment here '''' - Correct Answer-In-line comment Multi-line comment What is the code for defining? How do you call it? - Correct Answer-def function_name_here():

indented code here function_name() color("color name") - Correct Answer-Changes Tracy's trail color. pensize(#) - Correct Answer-Changes Tracy's trail thickness. begin_fill() - Correct Answer-Starts filling in drawn shapes. end_fill() - Correct Answer-Stops filling in drawn shapes. circle(radius, extent, steps) - Correct Answer-Can control the radius, degrees, and number of points of a circle. Top Down Design - Correct Answer-a problem solving approach (also known as stepwise design) in which you break down a system to gain insight into the sub-systems that make it up. variable_name = value - Correct Answer-Assigns a variable ex. color = input("Enter a color: ") for i in range(starting_num, ending_num, increase_by): - Correct Answer-alters the value of i by including a starting value, ending value, and a value to increase by on each iteration if statement - Correct Answer-The common programming structure that implements "conditional statements". Ex. if condition: If true, run the commands here(indented) elif condition: If first condition is false, if true, run the commands here else: If no other conditions are true, if true, run the commands here while loop - Correct Answer-a programming construct used to repeat a set of commands (loop) as long as (while) a boolean condition is true ex. while condition: Run commands here (indented) Printing in Python - Correct Answer-Displays what is told to print.

round(x) round(x, n) - Correct Answer-will round the float x to 0 decimal places. will round the float x to n decimal places Return Command - Correct Answer-is used when a function is ready to return a value to its caller. Infinite loops - Correct Answer-created if the exit condition of the while loop is never met, causing the code inside the while loop to repeat continuously. break - Correct Answer-a statement that immediately terminates a loop. continue - Correct Answer-a statement that skips to the top of the loop. Why use functions? - Correct Answer-Functions allow us to break our program into smaller parts, and make the program easier to understand. Namespace - Correct Answer-the collection of variable names that exist at a certain point in your code. Names don't exist throughout the entire program, they only exist within a certain namespace. Scope - Correct Answer-where the variable exists within a program. If a variable doesn't exist at a certain place, then it is "out of scope." Parameters - Correct Answer-pieces of information that you can give to functions when you call them. Exceptions - Correct Answer-run time errors in a program. By default, they stop the program. Try and Except - Correct Answer-programming constructs that can be used to gracefully handle exceptions so that a program can continue in spite of them. Indexing - Correct Answer-assigns a number to each character or space within the string. Begin at zero from left to right, and -1 from the right to left.

  • use brackets [ ] not parentheses ( ). ex.

this will print the letter 'h'

s = "hi there!" print s[0] Slicing - Correct Answer-uses a range of indices to specify a portion of a string with an arbitrary length.

*If you leave the first part of the slice blank, python assumes you want to start at index zero. *If you leave the second part of the slice blank, python assumes you want to go to the end of the string. ex.

this will print the letters 'hi the' from the string

it includes all characters or spaces up to but not including index six

s = "hi there!" print s[:6] Immutability - Correct Answer-strings that can't be changed. *You can assign strings to variables, and reassign new strings to the same variable, but YOU CANNOT REASSIGN INDIVIDUAL CHARACTERS WITHIN A STRING. ex. WRONG RIGHT my_string = "hi there!" my_string = "hi there!" my_string[0] = "H" my_string = my_string[1:] len value - Correct Answer-returns the length of a specific string. letter - Correct Answer-a counter variable that holds each value as the loop iterates. in - Correct Answer-used in an if statement to see if a particular letter or sub string is in a string. String Methods - Correct Answer-Methods that belong to the String class that act on the string, such as lower(), isupper(), islower(), swapcase(), strip(), len(), count(), and find() lower() - Correct Answer-returns a lowercase version of the string it is called on isupper() - Correct Answer-returns true if a string is all uppercase letters islower() - Correct Answer-returns true if a string is all lowercase letters swapcase() - Correct Answer-returns a string which cash letter is the opposite case as the original string strip() - Correct Answer-returns a copy of the string you call it on, without any whitespace at the beginning or end