MOD1: H1 - H5 Flashcards

1
Q

What version of Python am I running?

A

Python 2.7 (That’s what the BOOK wants for an Answer.)

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

What is another word for a File “Folder”?

A

Directory

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

If I want to edit code in a Text Editor, I should use Microsoft Word or WordPad?

True
False

A

False

Rich Editors such as Word or Wordpad will destroy your code.
Use Code Editors such as Notepad++ for Windows or TextWrangler on Mac.

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

Through the command line, create a new folder called “projects” in your home folder. Then, change into that directory and create another folder called “python”.

A
  1. Open CMD Line Terminal
  2. mkdir projects (dir - to confirm new projects directory)
  3. cd projects
  4. mkdir python (dir - to confirm new python directory)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In your text editor, create a new file called hello.py in your new python directory (the one you made in Exercise 1). Type print “Hello, world” into it and then save and close it. In your command line, see how big the file is.

A
  1. Open CMD Line Terminal
  2. cd projects
  3. cd python
  4. dir
  5. Find the [hello.py] File and look at the File Size info.

Answer: 24 bytes

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

A Mastery of Programming and High Level coding is necessary for most Cybersecurity positions?

True
False

A

False

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

Programming Awareness means that you can identify programming code, you understanding basic programming constructs and components, such as If/Then Statements and Loops, and can read code and understand in general what the code is trying to do?

True
False

A

True

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

Which Text Editor does the Textbook recommend for use with Python?

Notepad
Notepad++
WordPad
MS Word
Google Docs
A

Notepad++

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

When working your way through code examples in the Textbook and code presented as part of Canvas-Based Activities, you should copy and write the entire program before proceeding to test and debug your code?

True
False

A

False

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

Briefly explain the concept of Unit Testing and why it is important?

A

Improves the Quality of your code and helps you identify fixable errors and defects.

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

Define Knowledge Generalization?

A

The ability to transfer and utilize knowledge across multiple situations.
Takes practice to hone, but highly valued by employers.

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

How long can a number be?

A

Number Type is long, and it’s determined by how much memory your machine has. The more numbers it can keep in memory at one time, the longer the number can be.

This shouldn’t be an issue, you would need a number that’s big enough to fill up your available Memory AND your Had Drive, and this would be an enormous number even on the most under-powered machines.

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

What’s PEP?

A

Python Enhanced Proposal (PEP)
A document that describes a way in which Python can be made better.

Some don’t affect the language at all (such as the style guide), where as others may add or remove a feature from Python.

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

What is the difference between = and ==?

A

== denotes Equals To in a Math scripts to compare values.

= denotes assigning a value to a Variable.

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

What happens if you add an Integer and a Float?

A

A Float result is returned by Python.

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

What’s the result of this statement?

A

Basic Math - Order of Operations

2 * 3 first = 6
1 + 6 = 7

Answer is 7

17
Q

What is the difference between an Integer and a Float Variable?

A

Integer is a Whole Number
Float is going to have a Decimal.
Both are Variable Types that deal with Number Calculations

18
Q

What is a String?

A

A String is a Text Variable, the Text wraps within a set of Quotes. The Quotes could be either Single ‘ or Double “, but they Wrap the Text.
A String can be made of numbers, letters, spaces, symbols, or a combination of those - simply, the Output of a String is a Text Variable.
String would not be used in Mathematical Calculations.

19
Q

Explain the Python String - Function of .lower()?

A

The .lower() is a Method.
Method’s are used with Strings to change how the Text wrapped within Quotes are formatted.
In the case of .lower(), this Method will convert all the letters in the Text String to Lowercase.

20
Q

Is there any way to see all the things I can do with a String without looking it up online?

A
  1. Make sure you are in Python Shell and at the&raquo_space;> Prompt.
  2. s = “”
  3. help(type(s))
21
Q

Why are the Methods to remove whitespace from the beginning and end of a string called “right strip” and “left strip”? Why not “beginning” and “end”?

A

In quite of few languages text isn’t printed from left to right.
Arabic and Hebrew are both written from right to left, where as many Eastern scripts are written from top to bottom.
“Right” and “Left” are more universal than “beginning” and “end”.

22
Q

How big can a String be?

A

Depends on how much Memory and Hard Drive space your computer has.
Some languages limit the size of a string, but in Python - there is no hard limit.
In theory, one string in your program could fill up your whole Hard Drive!

23
Q

What characters can be stored in Strings?

A

Alphabetic Characters, Numbers, Symbols can all be stored in strings.
As well as Whitespace characters such as Spaces and Tabs.

24
Q

What math operators work in Strings?

A

Add, Multiply, and Equals using ==.

25
Q

What is the Backslash Character \ called?

A

Escape - and indicates that you want to include some special formatting, such as a Tab, New Line, a Single or Double Quote, or a Backslash like in a File Path Name or a Website.

26
Q

What if I don’t want to do anything in my EXCEPT Block?

A

Unlike ELSE, the EXCEPT Block is Required.
If you don’t want to do anything in that block, put a PASS Statement there.
Python will move past the Block and continue to execute your code.

try:
5 / 0
except:
pass

27
Q

What is the best way to make a Block of Code?

A

Hands down, SPACES are the best way.
You can add the Spaces in Manually by pressing the spacebar several times, or set your Editor to use Spaces when you press the Tab Key.
Spaces are interpreted the same way across Editors, but Tabs are often shown to be wider and narrower.
Each editor has a different way of doing this, but it’s generally under preferences.

28
Q

What if I only want to catch certain errors with a Try/Except?

A

Many times, you only want your Code to keep on going when it encounters certain errors, such as Dividing by Zero.

29
Q

How can you tell if a Section of Code belongs to one Block?

A

The Section of Code will Whitespaced/Indented the same amount looking like a Block, usually under the Statement Code.

30
Q

What is the difference between a TRY/EXCEPT and an IF/ELSE?

A

TRY will Execute until an Error is thrown. If that happens, then and only then will the Block of Code under the EXCEPT statement executes.

IF will only execute “If” the Statement is TRUE. If it is FALSE, the Code in the ELSE Statement will execute.

31
Q

When will an IF Statement return to the previous Block of Code?

A

Once an IF or ELIF Statement is TRUE, the Block of Code under the ELSE Statement has been run, or Python has run out of IF/ELIF Statements.

32
Q

Can a user enter something other than strings and numbers?

A

.input() – Can get all kinds of data from the command line, the drawback however is that the user needs to know exactly how to format the data. Typos will cause the program to crash.

.raw_input() – is much more forgiving.

33
Q

I was looking at some Python code another person wrote. Why is the percent sign (%) sometimes used to format strings?

A

The (%) sign plus a letter is an older way of formatting strings.
The .format() function was introduced in Python 2.6.

34
Q

What is the difference between .input() and .raw_input()?

A

.input() – gets raw data from the user, and this function will try to match it to the correct data type. (Integer, Float, String) But the User entering the data needs to know proper formatting, else Python may have issues interpreting it and throw errors, stopping the program from running.

.raw_input() – is much more forgiving, because the value will be saved as a String - that can then be later cleaned up through the code.

35
Q

You want the user to enter their social security number, but they probably don’t want the numbers to display on the screen as they type them. How would you get this information from the user securely?

A

Using the from getpass import getpass library.

36
Q

How would you remove extra whitespace from just the end of a string?

A

.rstrip() – Removes whitespace from the end (Right side) of the string.
.strip() – Removes it from the beginning AND the end of the string.

37
Q

How do you insert string into other strings without using the addition operator? How do you indicate where you want strings insterted?

A

The .format() function is used to insert strings into other strings.
The curly brackets { } indicate where you want values insterted.

38
Q

How do you convert a string to a Float? How about an Integer?

A

.float()

.int()