click below
click below
Normal Size Small Size show me how
IT 116 - Midterm
python scripting course containing questions that might appear on midterm
| Question | Answer |
|---|---|
| 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 function? | inside parentheses right after the function name |
| What do you call a sequence of characters? | string |
| What do you call a value written out directly inside the code? | literal |
| What do you call a statement that runs a function? | 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 |
| What's an expression? | anything that can be turned into a value |
| What's the name of the function used to read input from a keyboard? | input |
| 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: ")) |
| name three data types | integer, decimal, and string |
| what's the result of the following calculation in python's interactive mode: 7 / 2 | 3.5 |
| what's the result of the following calculation in python's interactive mode: 7 // 2 | 3 |
| what's the result of the following calculation in python's interactive mode: 7 % 2 | 1 |
| what's the result of the following calculation in python's interactive mode: 7 ** 2 | 49 |
| what's the result of the following calculation in python's interactive mode: (2+3)*5 | 25 |
| what arithmetic operators have the highest precedence (parentheses are NOT operators)? | ** |
| What would you type at the end of a line if you wanted to continue a Python statement to the next line? | a backslash (\) |
| Write a Python expression that concatenates the string, "My name is " with a string variable "name" | "My name is " + name |
| Write a Python expression that concatenates the string, "The rate is " with a variable "rate" which is of type float. | "The rate is " + str(rate) |
| Write a SINGLE print statement, without using triple quotes, which prints: Line 1 Line 2 Line 3 | print("Line 1\nLine 2\nLine 3") |
| What are the only values that a boolean expression can have? | True and False |
| Write the Python boolean literals. | True and False |
| if you typed the following in Python's 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 greater value than 0 and less than 10 | num > 0 and num < 10 |
| What is the data type of the variable whose name "value_good" that is created by the following statement?: value_good = num > 0 | Boolean |
| 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 or False | True |
| 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's less than 0, print "Zero" otherwise. | if numb > 0: print ("Positive") elif numb < 0: print("Negative") else: print("Zero") |
| In the loop given, 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 |
| what do you call a loop that doesn't stop? | 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 |
| If the range is run with the single argument 5, what are the list of numbers that would be created? | 0, 1, 2, 3, 4 |
| If the range is run with two arguments 1 and 5, what are the list of numbers created? | 1, 2, 3, 4 |
| If range is run with three arguments: 1, 10, and 2, what are the list of numbers 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 |
| what do you call the variables that are listed inside the parentheses of a function header? | Parameters |
| 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's 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 |
| 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 |
| Where do parameters get their values? | from the corresponding argument in the function call |
| What do you call the expressions (values), inside a function call? | arguments |