Download Python Coding Study Guide and more Exams Nursing in PDF only on Docsity! Final Exam - Python Coding Study Guide What will be the result of the following Python 3 statement? temperature = "3" + "5" - correct answer ✔✔' 35 ' What will be the output of the following code in Python 3? number = 6 number = number + 4 lucky_number = 10 * number print(lucky_number/number) - correct answer ✔✔10 What is the output of the following code in Python 3? print("Ozymandius"[2:4]) - correct answer ✔✔ym What is the output of the following code in Python 3? print(5>= 5) - correct answer ✔✔True What is the output of the following code in Python 3? animals = ["mammal","reptile","insect","fish"] animals.insert(3,"bird") print(animals) - correct answer ✔✔['mammal','reptile','insect','bird','fish'] What is the output of the following code in Python 3? print(17%5) - correct answer ✔✔2 Which of the following Python 3 instructions will produce the output Hello World? Print("Hello World") print "Hello World" print "Hello World" print("Hello World") - correct answer ✔✔print("Hello World") What character(s) is used at the start of a line in Python to indicate that what follows should be treated as a comment? - correct answer ✔✔# Which of the following is a type in Python? int bool list All of the above - correct answer ✔✔All of the above A fragment of code that causes a data type to be evaluated? - correct answer ✔✔Expression A single unit of code that the Python interpreter can execute? - correct answer ✔✔Statement What is the output of the following code in Python 3? print(1 and 0) - correct answer ✔✔0 If we have just 1 + 1 what are the outcome in command prompt (Shell Mode) and script? - correct answer ✔✔2 and *blank* What are the different types in Python? - correct answer ✔✔Integer, Floating Point Number, String, Boolean, List Data type for text and contained within quotation marks - correct answer ✔✔String; can consist of: Letters (both uppercase and lowercase); numbers; special characters; spaces; or combo of above What is the difference/similarities between string and list - correct answer ✔✔String data types consist of a sequence of characters. They are similar to the list data type. The main difference between the two is that a list can contain any data type, while string can only contain characters. Declared by assigning a sequence of values between square brackets to a variable. - correct answer ✔✔List. Values in a list can be of any data type including integers, strings, or a mix of data types including other lists. Operators - correct answer ✔✔Special symbols that represent operations that can be performed on data. Each data type supports a set of operations. Some are supported by multiple different data types, but the results of the operation may differ. greeting = "hello world" greeting[2:4] - correct answer ✔✔ll vegetable = ["tree", "flower"] for i in vegetable: print(i) - correct answer ✔✔tree flower Iteration addresses the values in the list sequentially The value at that point in the sequence - correct answer ✔✔Indexing animal = ["mammal", "reptile", "fish", "bird", "insect"] animal[2:4] - correct answer ✔✔['fish','bird'] Takes an argument and returns a value - correct answer ✔✔Method What is the basic syntax of a Method? - correct answer ✔✔Dot notation: <object>.<method-name>(<parameter1>, <parameter2>, ...) Object is typically a variable name What is the difference between .append and . extend? - correct answer ✔✔.append adds the string value "arthropod" to the end of the list, while .extend treats the string "bird" as a sequence of values and adds each character of the string as a separate value. Python interpreter always treats the values the user inputs at the keyboard as? - correct answer ✔✔A string. What is the purpose of indentation? - correct answer ✔✔To define blocks of code and at the same time enforce good coding practice. Each change in indentation is used to determine when a code block starts or stops. Define if statement and its structure: - correct answer ✔✔Executes a statement block based on results of a test expressed by a conditional statement Structure: if <test>: <code block> elif <test>: <code block> else: <code block> What is if-else? - correct answer ✔✔if statement can be used together with else What is if-elif? - correct answer ✔✔- if statement can be used together with one or more elif statements to set multiple tests. - The code block related to the test that is satisfied will be executed. - If none of the conditions is met, then either the else code block will be executed, or if there is no else code block, none of the conditional code blocks will be executed. Define while loop and its structure: - correct answer ✔✔Keeps executing a code block while the test is True while <test>: <code block> Define for loop and its structure: - correct answer ✔✔Execute a code block for a specified number of times. Structure: for <variable> in <iterable>: <code block> The <variable> is used as a counter that controls how many times the code block is executed. The <iterable> is a sequence of values such as a list or a string. The <variable> takes each successive value of the <iterable>.