Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

IT116

QuestionAnswer
What do you call one or more lines of code that perform a complete action? a statement
What do you call a series of statements that has a name and performs some task? a function
What do you call a value given to a function when it is run? an argument
Where do arguments appear in a call to a function? inside parentheses right after the function name
What do you call a sequence of characters? a string
What do you call a value written out directly inside the code? a literal
What do you call a statement that runs a function? a function call
What do you call a statement that gives a value to a variable? an assignment statement
What do you call a location in RAM with a name that holds a value? a variable
How do you create a variable in Python? with an assignment statement
What is an expression? anything that can be turned into a value
What are the four types of expressions? literals, variables, calculations, function calls
What is wrong with the following variable name?1st_try it begins with a digit
Is there a limit to the number of arguments you can use in a print function? no
What is the name of the function used to read input from the keyboard? input
Write an assignment statement that asks the user for his or her name and assigns it to the variable name. name = input("Please enter your name: ")
Write an assignment statement that asks the user for an integer, converts it to the correct data type and assigns it to the variable number. number = int(input("Please enter an integer: "))
Write an assignment statement that asks the user for a decimal number, converts it to the correct data type and assigns it to the variable number. number = float(input("Please enter a decimal number: "))
Name three data types. integer, decimal, string
What is the result of the following calculation in Python's interactive mode? 7 / 2 3.5
What is the result of the following calculation in Python's interactive mode? 7 // 2 3
What is the result of the following calculation in Python's interactive mode? 7 % 2 1
What is the result of the following calculation in Python's interactive mode? 7 ** 2 49
What is the result of the following calculation in Python's interactive mode? 2 + 3 * 5 17
What is the result of the following calculation in Python's interactive mode? (2 + 3) * 5 25
What arithmetic operators have the highest precedence? **
What arithmetic operators have the 2nd highest precedence? *, /, //, %
What arithmetic operators have the 3rd lowest precedence? +, -
What would you type at the end of a line if you wanted to continue a Python statement to the next line? \
Write a Python statement that prints the word "hello" but does not advance to the next line. print("hello", end="")
Write a Python statement that prints 1, 2, 4 print(1, 2, 3, sep=", ")
Write a Python expression that concatenates the string "My name is " with the string variable name. "My name is " + name
Write a Python expression that concatenates the string "The rate is " with the variable rate which is of type float. "The rate is " + str(rate)
Write a SINGLE print statement, without using triple quotes or concatenation, which prints The path is C:\temp\memo.txt. print("The path is C:\\temp\\memo.txt.")
Write a SINGLE print statement, without using triple quotes or concatenation, which prints She said "I'm OK" print("She said \"I\'m OK\"")
Write a SINGLE print statement, without using triple quotes, which prints Line 1 Line 2 Line 3 with newlines between them print("Line 1\nLine 2\nLine 3")^
Write an if statement that prints "Too big" if the value of the variable number is greater than 100. if number > 100: print("Too big")
What are the only values that a boolean expression can have? True and False
Write the Python boolean literals. True and False
Write the boolean expression that is true if the value of the variable number_1 is greater than or equal to value of the variable number_2. number_1 >= number_2
Write an if statement that prints "Too big" if the value of the variable numb is greater than 1000. if numb > 1000: print("Too big")
Write an if/else statement that prints "Positive" if the value of the variable numb is greater than or equal to 0, and prints "Negative" if it is not. if numb >= 0: print("Positive") else: print("Negative")
Write an if/elif/else statement that prints "Positive" if the value of the variable numb is greater than 0, and prints "Negative" if it is less than 0 and print "Zero" otherwise. if numb > 0: print("Positive") elif numb < 0: print("Negative") else: print("Zero")
If you typed the following in the Python interactive mode, what would the result be? "foo" < "bar" False
If you typed the following in the Python interactive mode, what would the result be? "sam" == "Sam" False
If you typed the following in the Python interactive mode, what would the result be? 5 != 6 True
Write a Python expression that evaluates to True if the variable whose name is num has a value greater than 0 and less than 10. num > 0 and num < 10
Write a Python expression that evaluates to True if the variable whose name is num has a value greater than or equal to 0 and less than or equal to 10. num >= 0 and num <= 10
What is the data type of the variable whose name is value_good that is created by the following statement? value_good = num > 0 boolean
What is the boolean value of the following expression? 5 and 0 False
What is the boolean value of the following expression? "a" or "" True
True What is the boolean value of the following expression? not 5 False
If you typed the following in Python's interactive mode, what would the result be? not False True
If you typed the following in Python's interactive mode, what would the result be? True and False False
If you typed the following in Python's interactive mode, what would the result be? True or False True
If you typed the following in Python's interactive mode, what would the result be? not True False
In the loop below, what happens each time the boolean expression after the keyword while evaluates to true? while num < 10: num = num + 1 the value of num increases by 1
If the value of the variable num is 0 before entering the loop above, how many times does the indented statement run? 10
If the value of the variable num is 0 before entering the loop above, what is the value of the variable num after the loop stops running? 10
What happens in a while loop when the boolean expression after the keyword while becomes false? the loop stops
What is unusual about the following code? num = 5 while num > 0: print(num) it will never stop
What do you call a loop that does not stop? an infinite loop
If you want to stop a Python script running on Unix, what do you do? Control C
Will a while loop with the following header ever stop? while True: no
What do you call the process of checking that a value entered by a user is correct? data validation
What do you call a statement that contains other statements? a compound statement
What comes after the keyword in in a Python for loop? a list of values
Where does the loop variable in a for loop get its values? from the list of values after in
If range is run with the single argument 5, what is the list of numbers that would be created? 0, 1, 2, 3, 4
If range is run with the two arguments 1 and 5, what is the list of numbers that would be created? 1, 2, 3, 4
If range is run with the three arguments 1, 10 and 2, what is the list of numbers that would be created? 1, 3, 5, 7, 9
If range is run with only one argument, what does that argument specify? one more than the last number in the list
If range is run with two arguments, what does the first of the two arguments specify? the first number in the list
If range is run with three arguments, what does the third of the three arguments specify? the difference between each number in the list
Write a for loop that prints the values from 1 to 10, each on a separate line. for number in range(10): print(number + 1)
Write a for loop that prints the values from 10 to 1, each on a separate line. for number in range(10, 0, -1): print(number)
If you were calculating a running total, which would be stored in a variable named total, what value would you assign to this variable at the start of the program? 0
What is the augmented assignment operator that adds the value on its right to the value of the variable on its left and assigns that new value to the variable? +=
What is the augmented assignment operator that subtracts the value on its right from the value of the variable on its left and assigns that new value to the variable? -=
What is the augmented assignment operator that multiples the value on its right by the value of the variable on its left and assigns that new value to the variable? *=
What is the augmented assignment operator that performs regular division on the value of the variable to its left by the value on its right and assigns that new value to the variable? /=
What is the augmented assignment operator that performs integer division of the value of the variable on its left by the value on its right and assigns that new value to the variable? //= Write a function header for function named max that takes two integers as parameters.
Write an assignment statement that uses a function call to the function max, which takes two arguments, to give a value to the variable maximum. Use the values 5 and 10 in the function call. maximum = max(5, 10)
What is a void function? a function that does not return a value
What do you call the functions that are always available in Python and DO NOT have to be imported? built-in functions
If you wanted to use the functions in the math module inside your script, what statement should appear at the top of the script? import math
If you wanted to print the value of pi from the math module, what statement would you use? print(math.pi)
Write the a function call that will return the value of the sine of π. The sine function in the math module is sin math.sin(math.pi)
What do you call a variable that is defined OUTSIDE any function? a global variable
Can a function use a variable defined outside any function? yes
Are the series of numbers created by the functions in the random module really random? no. they are a pseudorandom number sequence
If you wanted to use the functions in the random module inside your script, what statement should appear at the top of the script? import random
If you wanted to simulate the throw of a die using the randint function of the random module, what would you use as the function call? random.randint(1,7)
Can a return statement return more than one value? yes
What do you call the initial value given to an algorithm used to generate "random" numbers. seed
What do you call a variable that is defined inside a function? a local variable
If a variable is defined inside a function, can another function see the value of that variable? no
What do you call the variables that are listed inside the parentheses of a function header? parameters
Where do parameters get their values? from the corresponding argument in the function call
Write the function header for a function named calculate_interest that has two parameters: principle and interest. def calculate_interest(principle, interest):
What do you call the expressions (values), inside a function call? arguments
What is the augmented assignment operator that adds the value on its right to the value of the variable on its left and assigns that new value to the variable? +=
If you were calculating a running total, which would be stored in a variable named total, what value would you assign to this variable at the start of the program? 0
If you want to stop a Python script running on Unix, what do you do? control c
Name the four types of expressions. literals, variables, calculations, function calls
Write the SINGLE Python statement you would use to return True if the parameter number_1 were equal to the parameter number_2, but otherwise return False. return number_1 == number_2
Write a SINGLE Python statement to return True if the parameter number were less than 0, but otherwise return False. return number < 0
What appears after return in a return statement? an expression
Write the SINGLE Python statement you would use to return the value of the expression interest * principle from within a function return interest * principle
Write get_positive which takes no parameter and returns a number greater than 0. Ask the user for a number and convert it to an integer, then it should keep looping until it gets a number that is greater than 0 + returns that number. def get_positive(): number = int(input("Integer greater than 0: ")) while number <= 0: print(number, "is not greater than 0") number = int(input("Integer greater than 0: ")) return number
What is a file? a linear arrangement of data on a storage medium
What are the two things that uniquely specify a file? name and location
What must you create to work with a file in Python? a file object
What is the Python function that creates the thing you need to work with a file? open
What two things does the open function do? creates a file object and returns a reference to it
What two pieces of information do you need to give the open function as arguments? pathname and access mode
What are the three ways you can open a file? reading, writing, and appending
What are the two things that make up a pathname? path to the file (location) and name of file
If I have a variable named file, what is the Python statement I would write to write the word "hello" to the file? file.write("hello")
What is the name of the method used to read the ENTIRE contents of a file? read
Write the Python statement that would create a file object for the file scores.txt for reading and assign it to the variable scores_file. scores_file = open("scores.txt", "r")
Write the Python statement that would create a file object for the file scores.txt for writing and assign it to the variable scores_file. scores_file = open("scores.txt", "w")
Write the Python statement that would create a file object for the file scores.txt for appending and assign it to the variable scores_file. scores_file = open("scores.txt", "a")
What happens when you use the append access mode on a file? adds text to the bottom of the file
If you wanted to read a SINGLE LINE of a file for which you had the file variable scores_file and store it in the variable line what Python statement would you write? line = scores_file.readline()
What is the empty string? a string with no characters in it
What does readline() return when it gets to the end of the file? the empty string
What must you do if you want to write an integer to a text file? convert it into a string
What must you do if you read "87" from a text file and want to add it to another number? convert it to an integer
Write a for loop that reads and prints a file. Assume you have already created a file object and have stored a reference to it in the variable file. for line in file: print(line.rstrip())
What is the name of the program that we use to run Python scripts? python3
What permissions does an account need on a Python script to be able to run it without typing the name of the Python interpreter on the command line? I want the names of the permissions. read and execute permissions
What is the name of the special line we use to run a Python program without directly calling the interpreter? the hashbang/shebang line
Where must this special line appear? the first line of the script
What are the first two characters of this special line? #!
What must follow these two characters? I don't want the actual value, I want you to describe what it is. the absolute pathname of the Python interpreter
What is a record? the complete set of data about some event or thing
What are the individual pieces of data in a record called? fields
What type of loop do we use to read records? a for loop
What is the string method that can be used to remove the newline character at the end of a line? rstrip
What do you call an error caused by code that does not follow the rules of the Python language? a syntax error
What do you call an error that causes the code to give incorrect results? a logic error
What do you call an error that occurs when a value in a Python statement causes the statement to fail? a runtime error
What does the Python interpreter do when it comes upon a runtime error? creates an exception object
When does the Python interpreter create an exception object? when a runtime error occurs
What type of statement can be used to deal with an exception? a try/except statement
What should you put in the first block of a try/except statement? any code that might cause a runtime error
What should you put in the second block of a try/except statement? code that deals with the exception
What happens when an exception is encountered in the try block of a try/except statement? stops running the code in the 1st block and jumps to the code in the 2nd block
When the Python interpreter comes across a runtime error inside the try bloc of a try/except statement, what does the interpreter do? stops executing the code inside the try block and executes the code in the corresponding except block
Can the statements inside a try block raise more than one kind of exception? yes
If the code inside the try block can create more than one type of runtime error, what must you do if you want to do different things for each possible runtime error? create an except block for each possible exception type
If you had an except block that began except ValueError val_err: how would you print the error message contained in the exception object? print(val_err)
When is the code in the ELSE block of a try/except statement executed? after all the statements in the try block have run without raising an exception
When is the code in the FINALLY block of a try/except statement executed? after all the statements in the try block and all exception handlers have run
What do you call the statements inside an except block? the exception handler
What do you call a collection of things stored one right after another? a sequence
What is a list? a sequence object that CAN be changed
What is a tuple? a sequence object that CANNOT be changed
What do you call the individual values in a list? elements
Do the values in a list all have to be of the same type? no
What is the name of the list conversion function? list
Write an assignment statement that creates an empty list and assigns it to the variable empty. empty = []
Write an assignment statement that creates a list of the first 5 integers and assigns it to the variable l1. l1 = [1, 2, 3, 4, 5]
What expression would you write to get the number of values in the list l1? len(l1)
What list method would you use to add a value to the end of a list? append
Write a Python expression that creates a slice containing the second through the fourth elements of the list l1. l1[1:4]
Write a Python expression that evaluates to True if the list l1 contains the value 4. 4 in l1
Write a Python statement to add 6 to the list l1. l1.append(6)
Write a Python statement that sorts the list l1. l1.sort()
Write a Python expression that gives the largest value in the list l1. max(l1)
Write a Python expression that gives the smallest value in the list l1. min(l1)
Write a Python statement that creates a new list, l2, that has all the elements of the list l1 in the same order. l2 = l1[:]
Can a function that is given a list as a parameter and does not have a return statement change the list given as a parameter? yes
If l1 and l2 are list variables, write a Python statement that creates the new list l3 that consists of all the elements in l1 followed by all the elements in l2. l3 = l1 + l2
Write an expression that evaluates to True if the string "ox" is contained in the string pointed to by the string variable team. "ox" in team
Write an expression that evaluates to True if the string "ox" is NOT contained in the string pointed to by the string variable team. "ox" not in team
What string method returns a new string with all characters converted to lowercase? lower()
What string method returns a new string with all characters converted to uppercase? upper()
What string method and argument would you use to remove the linefeed character at the end of a string? rstrip()
What does strip() do? returns a new string with whitespace characters at the beginning and end of the string removed
What string method and argument would you use to create a list from a line in a CSV file? split(',')
Are strings sequences? yes
What are the elements of a string? characters
Write a Python expression that returns the FIRST character in the string team. team[0]
Write a Python expression that returns the LAST character in the string team. team[len(team) - 1]
Can you use a negative number as an index to a string? yes
If the string variable team is assigned the value "Red Sox", what does the following expression return? team[-1] x
Can a string be changed? no, strings are immutable
Write a Python expression that returns a string consisting of the FIRST 3 characters in the string team. team[0:3] or team[:3]
Write a Python expression that returns a string consisting of the LAST 3 characters in the string team. team[-3:]
Write a loop to print the individual characters of the string team with each character appearing on a separate line. for i in range(len(team)): print(team[i])
Can a list be an element of a list? yes
What do you call a list each of whose elements is a list? a two-dimensional list
What is a tuple? a sequence that cannot be changed
Write a Python statement that creates a tuple assigned to the variable numbers containing the integers 1 through 5. numbers = (1, 2, 3, 4, 5)
Write a Python statement that creates an empty tuple assigned to the variable empty. empty = ()
Write a Python statement creates a tuple containing only the integer 1 and assigns it to the variable t_1. t_1 = (1,)
Does does a tuple have an append method? no
Can you concatenate two tuples? yes
Does a tuple have a sort method? no
What is the name of the tuple conversion function? tuple
If l1 is a list, what is l2 after the following statement is executed? l2 = l1 a brand new list variable pointing to the same list as l1
Write a Python statement that creates a new list, l2, that has all the elements of the list l1 in the same order. l2 = l1[:]
Can a function that is given a list as a parameter and does not have a return statement change the list given as a parameter? yes
If l1 and l2 are list variables, write a Python statement that creates the new list l3 that consists of all the elements in l1 followed by all the elements in l2. l3 = l1 + l2
Write a loop that increases the value of all the integers in the list l1 by 2. for i in range(len(l1)): l1[i] += 2
What Python statements should you put inside the try block of a try/except statement? any statement that can cause a runtime error
Can the statements inside a try block raise more than one kind of exception? yes
When is the code in the else block of a try/except statement executed? after all the statements in the try block have run without raising an exception
When is the code in the finally block of a try/except statement executed? after all the statements in the try block and all exception handlers have run
What do you call a collection of things stored one right after another? a sequence
What is a list? a sequence object that CAN be changed
What is a tuple? a sequence object that CANNOT be changed
Write an assignment statement that creates an empty list and assigns it to the variable empty. empty = []
Write an assignment statement that creates a list of the first 5 integers and assigns it to the variable l1. l1 = [1, 2, 3, 4, 5]
What expression would you write to get the number of values in the list l1? len(l1)
Created by: sumnerss
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards