Python Coding Study Guide, Exams of Nursing

This python coding study guide covers a wide range of topics, including basic data types, operators, control structures, functions, and more. It provides sample code snippets and explanations to help students understand the fundamental concepts of python programming. The guide is designed to prepare students for a final exam, covering topics such as string manipulation, list operations, conditional statements, loops, and recursion. By studying this document, students can gain a solid understanding of python syntax, logic, and problem-solving techniques, which are essential for success in python-based programming courses or projects.

Typology: Exams

2023/2024

Available from 10/17/2024

studyclass
studyclass 🇺🇸

1

(1)

28K documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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?
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

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

Items in a dictionary are... - correct answer ✔✔unordered so they cannot be referenced using their ordinal position...the actual order of the items is unpredictable. What results from "3" + "5"? Why? - correct answer ✔✔' 35'. Because they are surrounded by quotation marks, the interpreter treats the values as letters and concatenates them. What is 6 + 10 / 2? What is it called when calculation is correct but not meant for this result? - correct answer ✔✔11. Semantically Incorrect. Consider the following: lucky_number = 42 print(lucky_number) 42 What is lucky_number in this case? - correct answer ✔✔A variable: gives a name to a value. Consider the following: lucky_number = lucky_number * 2 print(lucky_number) 84 What happened? - correct answer ✔✔Assigned value of lucky_number * 2 to variable lucky_number. This changes the value of the variable lucky_number. Variable names are case sensitive. Single unit of code that the Python interpreter can execute - correct answer ✔✔Statement Any fragment of code that causes a data type to be evaluated - correct answer ✔✔Expression

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"]

elif : else: 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 : Define for loop and its structure: - correct answer ✔✔Execute a code block for a specified number of times. Structure: for in : The is used as a counter that controls how many times the code block is executed. The is a sequence of values such as a list or a string. The takes each successive value of the .

What is another type of ? What does this do? - correct answer ✔✔range() function Will iterate over a sequence of numbers range(n) This function will generate an iterator starting with 0 and ending at n 1.‐ You can also specify a starting position and an increment for each iteration: range(, n,) Function - correct answer ✔✔Sequence of instructions that can be called by a name What is the purpose for the command, def? - correct answer ✔✔You can create your own functions. The same rules apply for function names as for variable names. A function that takes no arguments needs to be defined with empty parentheses. What is the purpose for the command, return? - correct answer ✔✔A function can return a value. Scope - correct answer ✔✔Variables used in a function that are local to the function. A variable is local to that function so it cannot be referenced outside of the function. If you want to the function to return a value, you need to use the return command. Here is an example of a script. What does this script do? def lucky_number(): import random x = random.randrange(10) print("Your lucky number is: ",x) lucky_number() - correct answer ✔✔When a function calls other functions.