Python Programming: File Handling, Exceptions, and JSON, Exams of Nursing

A comprehensive overview of file handling, exception handling, and json manipulation in python. It covers essential concepts such as reading and writing files, handling errors, and using the json module for data serialization and deserialization. Numerous examples and exercises to reinforce understanding and practical application.

Typology: Exams

2023/2024

Available from 12/14/2024

mad-grades
mad-grades 🇺🇸

3.7

(3)

9.2K documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Final Exam Quizzes Misy 5315
When working with the information in a text file, the first step is to: - correct answer read the file into
memory
This module allows you to save user data so it isn t lost when your program stops running. It is the
___________ module. - correct answer json
Python has a _____ statement that tells it to do nothing in a try-except block. - correct answer pass
Strings can be written directly to a file with the write method, but numbers must be converted to strings
before they can be written. - correct answer True
The following statement "with open(filename, 'a') as file_object:" opens a file in ________ mode. -
correct answer append
If you need to use backslashes, you can escape each one in the path, like this: "C:\\path\\to\\file.txt". -
correct answer True
____________ is improving your code by breaking it up into a series of functions that have specific jobs.
- correct answer append
Python can only write strings to a text file. - correct answer True
Python's __________ method removes, or strips, any whitespace characters from the right side of a
string. - correct answer strip()
To add content to a file instead of writing over existing content, you can open the file in ________ mode.
- correct answer append
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Python Programming: File Handling, Exceptions, and JSON and more Exams Nursing in PDF only on Docsity!

Final Exam Quizzes Misy 5315

When working with the information in a text file, the first step is to: - correct answer read the file into memory This module allows you to save user data so it isn t lost when your program stops running. It is the ___________ module. - correct answer json Python has a _____ statement that tells it to do nothing in a try-except block. - correct answer pass Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written. - correct answer True The following statement "with open(filename, 'a') as file_object:" opens a file in ________ mode. - correct answer append If you need to use backslashes, you can escape each one in the path, like this: "C:\path\to\file.txt". - correct answer True ____________ is improving your code by breaking it up into a series of functions that have specific jobs.

  • correct answer append Python can only write strings to a text file. - correct answer True Python's __________ method removes, or strips, any whitespace characters from the right side of a string. - correct answer strip() To add content to a file instead of writing over existing content, you can open the file in ________ mode.
  • correct answer append

"In quantum computing, the circuit behavior is governed by __________ physics or _________ mechanics." - correct answer quantum,quantum A qubit will be both 1 and 0 at the same time until it is measured which is defined as __________. - correct answer superposition Quantum transistors which are the basic building blocks of quantum computers are called __________. - correct answer SQUID Conventional computing uses __________ code i.e. bits 0 or 1 to represent information. - correct answer binary __________ transistors are the basic building blocks of conventional computers. - correct answer CMOS "Quantum computing use Qubits i.e. 0, 1 and _________ state of both 0 and 1 to represent information. " - correct answer superposition The physical representation of a qubit can be denoted using a sphere called the _________ sphere. - correct answer Bloch __________ computing is based on the classical phenomenon of electrical circuits being in a single state at a given time, either on or off. - correct answer Conventional or classical __________ transistors are the basic building blocks of conventional computers. - correct answer CMOS Albert Einstein opposed the view of quantum entanglement and called it __________. - correct answer spooky action at a distance According to the __________ thesis, quantum computation algorithms can be simulated on classical computers with a probabilistic approach. - correct answer Church Turing

The quantum algorithm solving __________ problem, usually called __________ algorithm, served as the inspiration for Shor's algorithm. - correct answer "Simon's,Simon's" Moore s Law absolutely applies to quantum computing. - correct answer False Shor's algorithm can be used to hack RSA encryption today. - correct answer True __________ Algorithm was the first to show a separation between the quantum and classical difficulty of a problem. - correct answer Deutsch-Josza To run Shor's Algorithm on a 1024-bit number requires two quantum registers, one of 2048 qubits and one of 1024. - correct answer True

  1. Whenever an error occurs that makes Python unsure what to do next, it creates a(n) _____ object. - correct answer A. Exception
  2. When trying to work with a file, once a file object representing the file is created, the ______ method can be used. - correct answer A. Read()
  3. A(n) ________ is the exception Python creates when it can't find the file it is trying to open. - correct answer FileNotFoundError
  4. The open() function returns a(n) ______ representing the file. - correct answer Object The open() function needs two arguments: the name of the file you want to open and what you plan to do with the file. - correct answer FALSE
  5. To add content to a file instead of writing over existing content, you can open the file in ____ mode. - correct answer Append
  6. ______ are special objects Python creates to manage errors that arise while a program is running. - correct answer Exceptions
  1. An unhandled exception in a python program will halt the program and show a(n) _______. - correct answer Traceback
  2. Using json.dump() and json.load() is a simple way to share data between two programs. - correct answer A. TRUE
  3. You cannot use a for loop on the file object to examine each line from a file one at a time. - correct answer A. True
  4. One common issue when working with files is handling missing files. - correct answer A. True
  5. Using relative paths, you can read files from any location on your system. - correct answer A. False Python's __________ method removes, or strips, any whitespace characters from the right side of a string - correct answer rstrip()
  6. When working with the information in a text file, the first step is to: - correct answer Read the file into memory
  7. "Every time your program depends on something external, such as user input, the existence of a file, or the availability of a network connection, there is a possibility of an exception being raised." - correct answer True
  8. When a program is running you typically store information the users provide in data structures such as lists and dictionaries. - correct answer True
  9. The JSON (________________________) format was originally developed for JavaScript. - correct answer A. JavaScript Object Notation
  10. __________ are special objects Python creates to manage errors that arise while a program is running.
  • correct answer Exceptions
  1. If the last line in a file is not terminated with \n, the readline method will return the line without \n. - correct answer A. True
  2. To get Python to open files from a directory other than the one where your program file is stored, you need to provide a(n) ____________. - correct answer A. File Path
  3. Python has a limit to how much data you can work with even if your system s memory can handle it. - correct answer False
  4. When Python reads from a text file, it interprets all text in the file as a string but you can work with numbers from the file without converting them. - correct answer A. False
  5. Text files can contain all of these EXCEPT: - correct answer A. Literary Images
  6. Using backslashes in a file path will cause an error because the backslash is used to escape characters in strings. - correct answer A. True
  7. This statement "with open(filename, 'w') as file_object:" will open a file in _________ mode. - correct answer A. Write
  8. Python has a _____ statement that tells it to do nothing in a try-except block. - correct answer A. Pass
  9. When working with a file you must read the entire contents of the file before you can do any. - correct answer A. False
  10. Coding exactly where a file is on your computer regardless of where the program that s being executed is stored is called a(n) __________ file path. - correct answer A. Absolute
  11. When working with a file in a program, the file must be in the same direcctory as the py file. - correct answer A. False
  12. Measuring a _____ bit turns it into a ______ bit. - correct answer A. "Quantum, classical"
  1. ______ transistors are the basic building blocks of conventional computers. - correct answer A. CMOS
  2. Quantum information storage and manipulation is based on Quantum Bit or qubit, which is based on the ______ of electron or polarization of a single photon. - correct answer A. Spin
  3. The famous thought experiment by _______ which explains the state of a quantum particle by taking a cat that is placed inside a box along with poisoned food. - correct answer A. Schrodinger
  4. The basic unit of information in a quantum computer is called a ______. - correct answer A. Qubit
  5. Quantum transistors which are the basic building blocks of quantum computers are called ______. - correct answer A. SQUID
  6. If a classical computer does n operations in 1 sec, a quantum computer can perform __ _____. - correct answer A. 2n operations
  7. In quantum computing, the circuit behavior is governed by ______ physics or ______ mechanics. - correct answer A. Quantum, quantum
  8. SQUID is the abbreviation for Superconducting Quantum Interference Device which are quantum transistors. - correct answer A. True
  9. A quantum computer has a bit is called a qubit that has state which is represented by this(these) symbols, __________. - correct answer A. |0> or |1> or both
  10. Conventional information storage and manipulation is based on the bit, which is based on _________ or charge; low is 0 and high is 1. - correct answer A. Voltage
  11. A qubit will be both 1 and 0 at the same time until it is measured which is defined as __________. - correct answer A. superposition
  1. Conventional computing uses __________ code i.e. bits 0 or 1 to represent information. - correct answer A. Binary
  2. X gate will flip the qubit which is just like a NOT gate in conventional computing and is sometimes called _______. - correct answer A. Bitflip
  3. ______ is a three-qubit gate which is similar to a CNOT gate but has two control qubits and one target qubit. - correct answer A. Toffoli gate (CCNOT gate)
  4. Simulators are quantum computers but operate on optical characteristics based on the probabilistic computing approach. - correct answer A. False
  5. Quantum Superposition is a phenomenon which helps us bias the measurement of a qubit towards the desired state or set of states. - correct answer False
  6. Multi-Qubit Gates act on more than one qubit and promote information exchange between ______. - correct answer A. Qubits
  7. A combination of gates on qubit registers is called a quantum circuit. - correct answer A. True
  8. _____ gate changes the base state of a qubit by making the probabilities of both basis states equal. - correct answer A. Hadamard
  9. Simulators can be used to code and execute quantum algorithms in a probabilistic fashion. - correct answer A. True
  10. The number of times your algorithm runs on a simulator is called __________. - correct answer A. Shots
  11. In quantum entanglement, the states of the particles will be correlated but not dependent on one another. - correct answer A. False
  1. Hadamard transform is used in the __________ circuit, so the output that qubit decides the output of the second qubit, where the two qubits are joined using a CNOT gate. - correct answer A. Teleportation
  2. Quantum __________ are visually represented as lines where each line represents a qubit. - correct answer A. Circuits
  3. Entanglement is a phenomenon that only classical computers can demonstrate. - correct answer A. False
  4. The __________ gate is a controlled not gate which is just like the classical NOT gate but it includes two qubits, a control qubit and a target qubit. - correct answer A. CNOT
  5. Quantum __________ is an application based on the entanglement phenomenon. - correct answer A. Teleportation
  6. According to the __________ thesis, quantum computation algorithms can be simulated on classical computers with a probabilistic approach. - correct answer A. Church Turing
  7. Qasm_simulator is __________ quantum assembly simulator. - correct answer A. IBMs
  8. Quantum __________ mimic the operations of quantum __________. - correct answer A. "simulators, computers"
  9. In Qiskit, the CNOT gate is referred to as cx which is an abbreviation for __________. - correct answer A. Controlled X-Gate
  10. Pauli X, Y, Z gates are multiple qubit gates. - correct answer True
  11. According to IBM, Quantum systems and quantum states are extremely _______. - correct answer A. Fragile
  1. __________ algorithm gives exponential speed up over well-known classical algorithms for factorizing.
  • correct answer A. Shor's
  1. The Rivest-Shamir-Adleman (RSA) algorithm is the most famous encryption algorithm which is still being used by many major companies and banks today. - correct answer A. True
  2. Shor's algorithm can be used to hack RSA encryption today. - correct answer A. False
  3. __________ is a basic building block for other famous algorithms. - correct answer A. Quantum Fourier Transform
  4. __________ algorithm was the first to show a separation between the quantum and classical difficulty of a problem. - correct answer A. Deutsch-Josza
  5. Moore s Law absolutely applies to quantum computing. - correct answer False
  6. Shor's algorithm is a quantum computer algorithm for finding the __________ factors of an integer. - correct answer A. Prime
  7. Grover's algorithm is one of the main reasons __________ is heavily investing in quantum technology.
  • correct answer A. Amazon