Lectures 5 to 6 - Revision Flashcards

(27 cards)

1
Q

What is a SCRIPT?

A

A script is a set of statements written in proghramming language designed to perform a specific task and stored in a file.

The statements are executed one after the other until the script is finished

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an IDE?

A

An Integrated Development Environment (IDE) is a software
application designed to help developers write, debug, test and
manage code. An IDE includes a code editor, a terminal interface
and a bunch of programming tools.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a SHELL?

A

A shell is a program that serves as an interface between a user and an operating system e.g Powershell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

UNIX Commands: How do you display the current working directory in the terminal

A

pwd

(print working directory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

UNIX Commands: How do you use the terminal to display a list of files and or directories within a directory?

A

ls

to show the list in your current location just use ls

to specifiy a directory within your location use
ls directoryname

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

UNIX Commands: What does the .. symbol mean in the terminal?

A

.. represents the parent directory
. represents the current directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

UNIX Commands: How do you use the terminal to create a new directory?

A

mkdir thendirectoryname

(make directory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

UNIX Commands: How do you use the terminal to delete (remove) an empty directory?

A

rmdir thendirectoryname

(remove directory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

UNIX Commands: How do you delete (remove) files?

A

rm thenfilename

(remove)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

UNIX Commands: How do you copy files or directories?

A

cp thendirectoryorfilename

(copy)

To copy and rename
cp filename.py newfilename.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

UNIX Commands: How do you move files or directories?

A

mv thendirectoryorfilename then destination location

(move)

If the file name is the same as one already existing in that directory the effect will be to rename it with copy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

UNIX Commands: How do you display the content of files?

A

cat thenfilename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

UNIX Commands: How do you manage a file or directory name that has spaces in it?

A

Put the whole file or directory name in double quotation marks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Python Libray?

A

A Python Library is a collection of pre-written code made available to use.You can use them in your Python programs to perform specific tasks meaning you do not need to create them from scratch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between a script and a program?

A

Both scripts and programs are sets of statements written in a programming language designed to perform specific tasks…. The words are often used interchangably. HOWEVER they are slightly different.
Typically SCRIPTS are:
- simpler
- usually for temporary tasks
- use a text interface terminal (programs use GUI)
- written in interpreted languages (Python, JavaScript or Bash) - whereas programs are written in compiled languages (e.g. Java, C++, C)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are interpreters and interpreting languages?

A

Interpreters are software tools that processes and executes statements one at a time.

Interpreted languages are programming languages that execute instructions directly and line by line, without the need for prior compilation into machine language (binary). Instead of converting the entire program into machine code at once, as compiled languages do, they interpret and execute each instruction on the fly.
Examples are Python, JavaScript or Bash

Mostly easier to write than compiled code. Modern computers = fast so the executable time is less relevant. Important part is time taken to write the code

17
Q

What are compilers and compiling languages?

A

Compilers are software tools that converts a program’s source code into machine code and saves it in an executable file that can be loaded and run directly by the computer chip.

A compiled language in terms of programming is a language where the source code is translated into machine code, or binary code, by a compiler before it is executed. This translation process produces an executable file that the computer’s processor can run directly, without the need for an interpreter at runtime.

Traditionally executable files run faster than interpreted code.

18
Q

What are SPECIFICATIONS (in sofware development)?

A

Specifications are detailed documents that describes what a program (script, component, module or entire systems) should do. Can be written in natural or formal language. Might include examples.

19
Q

What is a COMMENT?

A

A comment is text within a program that provides information about the code. It’s marked by delimiting punctuation and is ignored by the python interpreter. Format is not specified.

Two types. A BLOCK comment and a LINE comment

20
Q

What is a BLOCK comment?

A

A comment over multiple lines. Begins and ends with three consequetive quotation marks. Typically it is a long explanation about the next bit of code.

e.g. a good example of a header block comment is:
“””
File: hello.py
Description: Says hello
Author: Chris Bleakley
Date: 04/02/2025
Version: 1.0
“””

21
Q

What is a LINE comment?

A

A short comment over one line only. Begins with the hash symbol. Often introduces the next few lines or clarifies something at the end. Consequetive line comments can be used (like a block comment)

22
Q

What is an f string?

A

An f string is a FORMATTED STRING literal.

It allows you to embed expressions inside string literals, using curly brackets {}. i.e the curly brackets are used to delimit a variable whose content will be displayed. This makes it easier and more readable to format strings. The variable can be of any data type, can be formatted or can be replaced by an expression

23
Q

What is the recommended maximum line length in Python?

A

The recommended maximum line length in Python is 79
characters.

24
Q

What are programmers two goals?

A

Programmers have two goals:
1. Their code works (meets the specifications)
2. Their code is readable
Programmers spend 60-80% of their time reading code.
Always write code that is easy to read.

25
Where can I find guidelines regarding Python?
Python Enhancement Proposals (PEPs) are design documents that provide information to the Python community or propose changes to Python itself. They are the primary mechanism for proposing major new features, collecting community input on an issue, and documenting the design decisions that have gone into Python. Each PEP has a unique number assigned to it. . For example, PEP 8 is a well-known PEP that provides guidelines for writing Python code to ensure readability and consistency within the Python community. It covers topics like naming conventions, code layout, and more. The PEP 8 - Style Guide for Python Code. USE IT AS A REFERENCE WHEN WRITING CODE.
26
How do you test (verify) your script?
Run it with test data to test the results against expected results. Method: 1. Create a set of test data 2. Manually determine what the results should be based on the specification. 3. Run the test data through the program. 4. Compare the expected and actual results.
27
List some options for debugging your script
Debugging options: - Manually go through your scipt and use the PRINT and COMMENT functions. The function print allows you to temporarily inspect the values assigned to the variables. Inserting a hash symbol before an statement allows you to temporarily de-activate the suspicious code. This helps you to identify the error - Enter interactive mode using -i python script.py Interactive Mode allows the programmer to investigate the final values stored in the variables because it runs statements that report the values stored in the variables. - The Python Debugger: pdb using breakpoint() statement. The script is run as normal. When execution reaches the breakpoint() statement, Python pauses execution of the script and enters the Python Debugger mode (pdb). Python Debugger mode is interactive. The programmer can type in statements and access the script's data, just like in normal Interactive Mode. However, in addition, Python Debugger mode allows the programmer to run just the next line or the rest of the script